Google::ProtocolBuffers::Dynamic::Introspection - introspection API for classes
version 0.26
$message_def = Some::Class->message_descriptor; $field_def = $message_def->find_field_by_name('some_field'); $message_name = $message_def->full_name; $field_name = $field_def->full_name $enum_def = Some::Enum::Package->enum_descriptor; $value = $enum_def->values;
A simple introspection API wrapping uPB descriptor API.
Note that this API does not respect referential integrity; for example this snippet
$message_def = ...; $field_def = $message_def->find_field_by_name($name); $containing_def = $field_def->containing_type; die "Oops" if $message_def != $containing_def;
die()s because even if $message_def and $containing_def represent the same underlying entity, their are two distinct objects in Perl. This is true for all methods below returning an object.
die()
$message_def
$containing_def
The same applies to multiple invocations of the same method, for example
$message_def = ...; $field_def = $message_def->find_field_by_name($name); $field_def_again = $message_def->find_field_by_name($name); die "Oops" if $field_def != $field_def_again;
$name = $message_def->full_name;
The fully-qualified name of this message (including package and outer messages).
$count = $message_def->field_count;
The number of fields/oneofs. The number of fields includes fields declared in oneofs, but does not include the oneof declaration themselves.
$field_def = $message_def->find_field_by_number($number);
Returns the field matching the given number, or undef.
undef
$field_def = $message_def->find_field_by_name($name);
Returns the field with the given name, or undef.
$oneof_def = $message_def->find_oneof_by_name($name);
Returns the oneof with the given name, or undef.
$field_defs = $message_def->fields; $oneof_defs = $message_def->oneofs;
Returns all fields/oneof as an array reference.
$is_map = $message_def->is_map_entry;
True if this message is a key/value pair that Protocol Buffers 3 uses to represent a map entry.
$name = $field_def->name;
The short name of this field (the one used in the message definition).
$name = $field_def->full_name;
Same as name for regular fields, returns the fully-qualified name for extension fields.
name
$number = $field_def->number;
The field number as declared in the message definition.
$label = $field_def->label;
Returns the field label (whether the field is required, repeated or optional).
required
repeated
optional
Simple boolean accessors.
$protobuf_type = $field_def->descriptor_type;
Returns the field type as specified in the message declaration (note that this returns different types for, e.g. int32, sint32, fixed32 and sfixed32 fields).
int32
sint32
fixed32
sfixed32
$value_type = $field_def->value_type;
Returns the underlying field type (note that this returns the same int32 type for, e.g. int32, sint32, fixed32 and sfixed32 fields).
$value = $field_def->default_value;
The default value for this field (the type depends on field type). Returns undef for message/group fields, returns the default value for the underlying type for repeated fields.
$message_def = $field_def->containing_type;
Containing message (for extension fields this is the message being extended, not the message where the extension is declared).
$oneof_def = $field_def->containing_oneof;
Containing oneof definition, or undef if this field is not part of an oneof.
$enum_def = $field_def->enum_type; $message_def = $field_def->message_type;
For fields with type enum or message, returns the matching type definition, or undef if the fields is not a message/enum.
$name = $oneof_def->name;
$name = $oneof_def->full_name;
Same as name.
$count = $oneof_def->field_count;
The number of fields.
$field_def = $oneof_def->find_field_by_number($number);
$field_def = $oneof_def->find_field_by_name($name);
$field_defs = $message_def->fields;
Returns all fields as an array reference.
Containing message.
$name = $enum_def->full_name;
The fully-qualified name of this enum (including package and outer messages).
$value = $enum_def->default_value;
Default value for this enum.
$number = $enum_def->find_number_by_name($name);
Returns the integer value of the enum entry with the given name, or undef.
$name = $enum_def->find_name_by_number($number);
Returns the name of the enum entry with the given value, or undef.
$value_map = $enum_def->values;
Returns an hash reference containig all name/value pairs for this enum.
$name = $service_def->full_name;
The fully-qualified name of this service (including package).
$method_defs = $service_def->methods;
Returns all methods as an array reference.
$name = $method_def->name;
The short name of this method (the one used in the service definition).
$name = $method_def->full_name;
The fully-qualified name of this method (including package and service name).
$service_def = $method_def->containing_service;
Containing service definition.
$message_def = $method_def->input_type;
Input type for the method.
$message_def = $method_def->output_type;
Output type for the method.
$is_streaming_client = $method_def->client_streaming.
True if the service accepts streaming input (i.e. the input type has the stream annotation in the method definition).
stream
$is_streaming_server = $method_def->server_streaming.
True if the service produces streaming output (i.e. the output type has the stream annotation in the method definition).
All the constants below are available as Google::ProtocolBuffers::Dynamic::CONSTANT and can be exported either individually or using the :labels, :descriptor and :values exporter tags.
Google::ProtocolBuffers::Dynamic::CONSTANT
:labels
:descriptor
:values
Return value of the "label" method.
Return value of the "value_type" method.
Return value of the "descriptor_type" method.
Mattia Barbon <mattia@barbon.org>
This software is copyright (c) 2015-2016 by Mattia Barbon.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Google::ProtocolBuffers::Dynamic, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Google::ProtocolBuffers::Dynamic
CPAN shell
perl -MCPAN -e shell install Google::ProtocolBuffers::Dynamic
For more information on module installation, please visit the detailed CPAN module installation guide.