[protobuf-perl commit] r165 - in trunk: perl perl/lib perl/lib/Protobuf/Attribute perl/t perl/t/autogen perl/t/autogen/A...

1 view
Skip to first unread message

codesite...@google.com

unread,
Sep 25, 2008, 1:57:05 PM9/25/08
to protobuf-p...@googlegroups.com
Author: jeremywleader
Date: Thu Sep 25 10:55:49 2008
New Revision: 165

Modified:
trunk/perl/NOTES.txt
trunk/perl/TODO
trunk/perl/lib/Protobuf.pm
trunk/perl/lib/Protobuf/Attribute/Field.pm
trunk/perl/t/autogen/AppEngine/Service/MemcacheProto.pm
trunk/perl/t/autogen/ProtobufTestBasic.pm
trunk/perl/t/descriptors.t
trunk/protobuf/src/google/protobuf/compiler/perl/perl_generator.cc
trunk/protobuf/src/google/protobuf/descriptor.proto

Log:
A collection of minor fixes:
- Don't emit redundant "package foo; package foo;" if perl_message_package
and perl_file_package are identical.
- Emit "1;" at the end of each generated file, so "use" of the file will
succeed.
- Remove the left-over Python generation code which emits assignments
setting enum values in Generator::PrintTopLevelEnums.
- Use perl_message_package when generating full_name for enums and messages.
- Fix a templating typo in Generator::FixForeignFieldsInExtension which
caused
a fatal error when generating code for unittest.proto
- Minor corrections and clarifications to comments in perl_generator.cc and
descriptor.proto.
- Renamed enum.fullname to enum.full_name, for consistency with
message.full_name. (Required a change to a test)
- Fix warnings: "Constant subroutine ProtobufTestBasic::TestAllTypes::
NestedEnum::FOO redefined at lib/Protobuf/Attribute/Field.pm line 44." by
not re-defining already defined enum setter methods in
Protobuf::Attribute::Field::install_accessors
- Cleaned up hack in Protobuf::Descriptor::_build_class_name.
- Removed a few stray tab characters from tests.


Modified: trunk/perl/NOTES.txt
==============================================================================
--- trunk/perl/NOTES.txt (original)
+++ trunk/perl/NOTES.txt Thu Sep 25 10:55:49 2008
@@ -97,3 +97,6 @@
>>> sres.SerializeToString()
'\x08\x01\x08\x02\x08\x03\x08\xfa\x01'

+How to run all the test .proto files through protoc (from the perl
directory):
+
+for i in t/data/*.proto ; do echo $i; protoc --perl_out=t/autogen -It/data
$i; done

Modified: trunk/perl/TODO
==============================================================================
--- trunk/perl/TODO (original)
+++ trunk/perl/TODO Thu Sep 25 10:55:49 2008
@@ -5,24 +5,12 @@
-- imports ("use" the perl_outer_package of the imported package)
-- negative enums are broken. see t/wire-numbers.t

-This noise:
-Constant subroutine ProtobufTestBasic::TestAllTypes::NestedEnum::FOO
redefined at lib/Protobuf/Attribute/Field.pm line 44.
-Constant subroutine ProtobufTestBasic::TestAllTypes::NestedEnum::BAR
redefined at lib/Protobuf/Attribute/Field.pm line 44.
-Constant subroutine ProtobufTestBasic::TestAllTypes::NestedEnum::BAZ
redefined at lib/Protobuf/Attribute/Field.pm line 44.
+Use ../protobuf/src/google/protobuf/test_util.cc to verify parsing of
+unittest.proto?

-This is still Python:
--FOREIGN_FOO = 4;
--FOREIGN_BAR = 5;
--FOREIGN_BAZ = 6;
--FOO1 = 1;
--BAR1 = 2;
--BAZ = 3;
--FOO2 = 1;
--BAR2 = 2;
--SPARSE_A = 123;
--SPARSE_B = 62374;
--SPARSE_C = 12589234;
--SPARSE_D = -15;
--SPARSE_E = -53452;
--SPARSE_F = 0;
--SPARSE_G = 2;
+Are nested_types and enum_types needed?
+
+Implement services and methods.
+
+Enhance makefiles to run protoc on .proto files and remove generated Perl
+files from svn.

Modified: trunk/perl/lib/Protobuf.pm
==============================================================================
--- trunk/perl/lib/Protobuf.pm (original)
+++ trunk/perl/lib/Protobuf.pm Thu Sep 25 10:55:49 2008
@@ -9,7 +9,7 @@
use Moose;

has 'name' => (is => 'rw', isa => 'Str');
-has 'fullname' => (is => 'rw', isa => 'Str');
+has 'full_name' => (is => 'rw', isa => 'Str');

has 'values' => (is => 'rw', isa
=> 'ArrayRef[Protobuf::EnumValueDescriptor]' );

@@ -44,12 +44,6 @@
sub _build_class_name {
my $self = shift;
my $name = $self->full_name;
-
- # TODO(bradfitz): Hack. temporary:
- $name =~ s/^appengine_api\./AppEngine::Service::/;
- $name =~ s/^appengine_datastore_v3\./AppEngine::Service::Datastore::/;
- $name =~ s/^appengine_entity\./AppEngine::Service::Entity::/;
- $name =~ s/^protobuf_unittest\./ProtobufTestBasic::/;

$name =~ s/\./::/g;
return $name;

Modified: trunk/perl/lib/Protobuf/Attribute/Field.pm
==============================================================================
--- trunk/perl/lib/Protobuf/Attribute/Field.pm (original)
+++ trunk/perl/lib/Protobuf/Attribute/Field.pm Thu Sep 25 10:55:49 2008
@@ -9,9 +9,9 @@
use namespace::clean -except => 'meta';

has field => (
- isa => "Protobuf::FieldDescriptor",
- is => "ro",
- required => 1,
+ isa => "Protobuf::FieldDescriptor",
+ is => "ro",
+ required => 1,
handles => [qw(is_repeated message_type enum_type)],
);

@@ -19,7 +19,6 @@
required => 1,
);

-
sub field_to_type_constraint {
my ( $class, $field ) = @_;

@@ -32,6 +31,8 @@
return type_constraint($field->type);
};

+our %generatedenumvalues = ();
+
after 'install_accessors' => sub {
my $self = shift;

@@ -39,9 +40,14 @@
my $class_name = $self->associated_class->name;
foreach my $value ( @{ $enum->values } ) {
my $fqname = join("::", $class_name, $enum->name,
$value->name);
- my $number = $value->number;
- no strict 'refs';
- *$fqname = sub () { $number };
+ # failing to fully qualify generatedenumvalues causes a weird
+ # error message about dereferencing an unused scalar
+ if (! exists $__PACKAGE__::generatedenumvalues{$fqname}) {
+ my $number = $value->number;
+ no strict 'refs';
+ *$fqname = sub () { $number };
+ $__PACKAGE__::generatedenumvalues{$fqname} = 1;
+ }
}
}
};

Modified: trunk/perl/t/autogen/AppEngine/Service/MemcacheProto.pm
==============================================================================
--- trunk/perl/t/autogen/AppEngine/Service/MemcacheProto.pm (original)
+++ trunk/perl/t/autogen/AppEngine/Service/MemcacheProto.pm Thu Sep 25
10:55:49 2008
@@ -20,7 +20,7 @@
## All nested enums:
our $_MEMCACHESERVICEERROR_ERRORCODE = Protobuf::EnumDescriptor->new(
name => 'ErrorCode',
- full_name => 'appengine_api.MemcacheServiceError.ErrorCode',
+ full_name => 'AppEngine::Service::ErrorCode',
values => [
Protobuf::EnumValueDescriptor->new(name => 'OK', index => 0, number =>
0, type => undef),
Protobuf::EnumValueDescriptor->new(name => 'UNSPECIFIED_ERROR', index
=> 1, number => 1, type => undef),
@@ -30,7 +30,7 @@

our $_MEMCACHESETREQUEST_SETPOLICY = Protobuf::EnumDescriptor->new(
name => 'SetPolicy',
- full_name => 'appengine_api.MemcacheSetRequest.SetPolicy',
+ full_name => 'AppEngine::Service::SetPolicy',
values => [
Protobuf::EnumValueDescriptor->new(name => 'SET', index => 0, number
=> 1, type => undef),
Protobuf::EnumValueDescriptor->new(name => 'ADD', index => 1, number
=> 2, type => undef),
@@ -42,7 +42,7 @@

our $_MEMCACHESETRESPONSE_SETSTATUSCODE = Protobuf::EnumDescriptor->new(
name => 'SetStatusCode',
- full_name => 'appengine_api.MemcacheSetResponse.SetStatusCode',
+ full_name => 'AppEngine::Service::SetStatusCode',
values => [
Protobuf::EnumValueDescriptor->new(name => 'STORED', index => 0,
number => 1, type => undef),
Protobuf::EnumValueDescriptor->new(name => 'NOT_STORED', index => 1,
number => 2, type => undef),
@@ -54,7 +54,7 @@

our $_MEMCACHEDELETERESPONSE_DELETESTATUSCODE =
Protobuf::EnumDescriptor->new(
name => 'DeleteStatusCode',
- full_name => 'appengine_api.MemcacheDeleteResponse.DeleteStatusCode',
+ full_name => 'AppEngine::Service::DeleteStatusCode',
values => [
Protobuf::EnumValueDescriptor->new(name => 'DELETED', index => 0,
number => 1, type => undef),
Protobuf::EnumValueDescriptor->new(name => 'NOT_FOUND', index => 1,
number => 2, type => undef),
@@ -64,7 +64,7 @@

our $_MEMCACHEINCREMENTREQUEST_DIRECTION = Protobuf::EnumDescriptor->new(
name => 'Direction',
- full_name => 'appengine_api.MemcacheIncrementRequest.Direction',
+ full_name => 'AppEngine::Service::Direction',
values => [
Protobuf::EnumValueDescriptor->new(name => 'INCREMENT', index => 0,
number => 1, type => undef),
Protobuf::EnumValueDescriptor->new(name => 'DECREMENT', index => 1,
number => 2, type => undef),
@@ -76,7 +76,7 @@

our $_MEMCACHESERVICEERROR = Protobuf::Descriptor->new(
name => 'MemcacheServiceError',
- full_name => 'appengine_api.MemcacheServiceError',
+ full_name => 'AppEngine::Service::MemcacheServiceError',
containing_type => undef,
fields => [
],
@@ -93,7 +93,7 @@

our $_MEMCACHEGETREQUEST = Protobuf::Descriptor->new(
name => 'MemcacheGetRequest',
- full_name => 'appengine_api.MemcacheGetRequest',
+ full_name => 'AppEngine::Service::MemcacheGetRequest',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -115,7 +115,7 @@

our $_MEMCACHEGETRESPONSE_ITEM = Protobuf::Descriptor->new(
name => 'Item',
- full_name => 'appengine_api.MemcacheGetResponse.Item',
+ full_name => 'AppEngine::Service::MemcacheGetResponse.Item',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -148,7 +148,7 @@

our $_MEMCACHEGETRESPONSE = Protobuf::Descriptor->new(
name => 'MemcacheGetResponse',
- full_name => 'appengine_api.MemcacheGetResponse',
+ full_name => 'AppEngine::Service::MemcacheGetResponse',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -170,7 +170,7 @@

our $_MEMCACHESETREQUEST_ITEM = Protobuf::Descriptor->new(
name => 'Item',
- full_name => 'appengine_api.MemcacheSetRequest.Item',
+ full_name => 'AppEngine::Service::MemcacheSetRequest.Item',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -215,7 +215,7 @@

our $_MEMCACHESETREQUEST = Protobuf::Descriptor->new(
name => 'MemcacheSetRequest',
- full_name => 'appengine_api.MemcacheSetRequest',
+ full_name => 'AppEngine::Service::MemcacheSetRequest',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -238,7 +238,7 @@

our $_MEMCACHESETRESPONSE = Protobuf::Descriptor->new(
name => 'MemcacheSetResponse',
- full_name => 'appengine_api.MemcacheSetResponse',
+ full_name => 'AppEngine::Service::MemcacheSetResponse',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -261,7 +261,7 @@

our $_MEMCACHEDELETEREQUEST_ITEM = Protobuf::Descriptor->new(
name => 'Item',
- full_name => 'appengine_api.MemcacheDeleteRequest.Item',
+ full_name => 'AppEngine::Service::MemcacheDeleteRequest.Item',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -288,7 +288,7 @@

our $_MEMCACHEDELETEREQUEST = Protobuf::Descriptor->new(
name => 'MemcacheDeleteRequest',
- full_name => 'appengine_api.MemcacheDeleteRequest',
+ full_name => 'AppEngine::Service::MemcacheDeleteRequest',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -310,7 +310,7 @@

our $_MEMCACHEDELETERESPONSE = Protobuf::Descriptor->new(
name => 'MemcacheDeleteResponse',
- full_name => 'appengine_api.MemcacheDeleteResponse',
+ full_name => 'AppEngine::Service::MemcacheDeleteResponse',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -333,7 +333,7 @@

our $_MEMCACHEINCREMENTREQUEST = Protobuf::Descriptor->new(
name => 'MemcacheIncrementRequest',
- full_name => 'appengine_api.MemcacheIncrementRequest',
+ full_name => 'AppEngine::Service::MemcacheIncrementRequest',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -368,7 +368,7 @@

our $_MEMCACHEINCREMENTRESPONSE = Protobuf::Descriptor->new(
name => 'MemcacheIncrementResponse',
- full_name => 'appengine_api.MemcacheIncrementResponse',
+ full_name => 'AppEngine::Service::MemcacheIncrementResponse',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -390,7 +390,7 @@

our $_MEMCACHEFLUSHREQUEST = Protobuf::Descriptor->new(
name => 'MemcacheFlushRequest',
- full_name => 'appengine_api.MemcacheFlushRequest',
+ full_name => 'AppEngine::Service::MemcacheFlushRequest',
containing_type => undef,
fields => [
],
@@ -406,7 +406,7 @@

our $_MEMCACHEFLUSHRESPONSE = Protobuf::Descriptor->new(
name => 'MemcacheFlushResponse',
- full_name => 'appengine_api.MemcacheFlushResponse',
+ full_name => 'AppEngine::Service::MemcacheFlushResponse',
containing_type => undef,
fields => [
],
@@ -422,7 +422,7 @@

our $_MEMCACHESTATSREQUEST = Protobuf::Descriptor->new(
name => 'MemcacheStatsRequest',
- full_name => 'appengine_api.MemcacheStatsRequest',
+ full_name => 'AppEngine::Service::MemcacheStatsRequest',
containing_type => undef,
fields => [
],
@@ -438,7 +438,7 @@

our $_MERGEDNAMESPACESTATS = Protobuf::Descriptor->new(
name => 'MergedNamespaceStats',
- full_name => 'appengine_api.MergedNamespaceStats',
+ full_name => 'AppEngine::Service::MergedNamespaceStats',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -490,7 +490,7 @@

our $_MEMCACHESTATSRESPONSE = Protobuf::Descriptor->new(
name => 'MemcacheStatsResponse',
- full_name => 'appengine_api.MemcacheStatsResponse',
+ full_name => 'AppEngine::Service::MemcacheStatsResponse',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -555,3 +555,5 @@

## Fix foreign fields in extensions:
## Services:
+
+1;

Modified: trunk/perl/t/autogen/ProtobufTestBasic.pm
==============================================================================
--- trunk/perl/t/autogen/ProtobufTestBasic.pm (original)
+++ trunk/perl/t/autogen/ProtobufTestBasic.pm Thu Sep 25 10:55:49 2008
@@ -15,7 +15,7 @@
## Top-level enums:
our $_FOREIGNENUM = Protobuf::EnumDescriptor->new(
name => 'ForeignEnum',
- full_name => 'protobuf_unittest.ForeignEnum',
+ full_name => 'ProtobufTestBasic::ForeignEnum',
values => [
Protobuf::EnumValueDescriptor->new(name => 'FOREIGN_FOO', index => 0,
number => 4, type => undef),
Protobuf::EnumValueDescriptor->new(name => 'FOREIGN_BAR', index => 1,
number => 5, type => undef),
@@ -28,7 +28,7 @@

our $_TESTENUMWITHDUPVALUE = Protobuf::EnumDescriptor->new(
name => 'TestEnumWithDupValue',
- full_name => 'protobuf_unittest.TestEnumWithDupValue',
+ full_name => 'ProtobufTestBasic::TestEnumWithDupValue',
values => [
Protobuf::EnumValueDescriptor->new(name => 'FOO1', index => 0, number
=> 1, type => undef),
Protobuf::EnumValueDescriptor->new(name => 'BAR1', index => 1, number
=> 2, type => undef),
@@ -45,7 +45,7 @@

our $_TESTSPARSEENUM = Protobuf::EnumDescriptor->new(
name => 'TestSparseEnum',
- full_name => 'protobuf_unittest.TestSparseEnum',
+ full_name => 'ProtobufTestBasic::TestSparseEnum',
values => [
Protobuf::EnumValueDescriptor->new(name => 'SPARSE_A', index => 0,
number => 123, type => undef),
Protobuf::EnumValueDescriptor->new(name => 'SPARSE_B', index => 1,
number => 62374, type => undef),
@@ -69,7 +69,7 @@
## All nested enums:
our $_TESTALLTYPES_NESTEDENUM = Protobuf::EnumDescriptor->new(
name => 'NestedEnum',
- full_name => 'protobuf_unittest.TestAllTypes.NestedEnum',
+ full_name => 'ProtobufTestBasic::NestedEnum',
values => [
Protobuf::EnumValueDescriptor->new(name => 'FOO', index => 0, number
=> 1, type => undef),
Protobuf::EnumValueDescriptor->new(name => 'BAR', index => 1, number
=> 2, type => undef),
@@ -83,7 +83,7 @@

our $_TESTALLTYPES_NESTEDMESSAGE = Protobuf::Descriptor->new(
name => 'NestedMessage',
- full_name => 'protobuf_unittest.TestAllTypes.NestedMessage',
+ full_name => 'ProtobufTestBasic::TestAllTypes.NestedMessage',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -104,7 +104,7 @@

our $_TESTALLTYPES_OPTIONALGROUP = Protobuf::Descriptor->new(
name => 'OptionalGroup',
- full_name => 'protobuf_unittest.TestAllTypes.OptionalGroup',
+ full_name => 'ProtobufTestBasic::TestAllTypes.OptionalGroup',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -125,7 +125,7 @@

our $_TESTALLTYPES_REPEATEDGROUP = Protobuf::Descriptor->new(
name => 'RepeatedGroup',
- full_name => 'protobuf_unittest.TestAllTypes.RepeatedGroup',
+ full_name => 'ProtobufTestBasic::TestAllTypes.RepeatedGroup',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -146,7 +146,7 @@

our $_TESTALLTYPES = Protobuf::Descriptor->new(
name => 'TestAllTypes',
- full_name => 'protobuf_unittest.TestAllTypes',
+ full_name => 'ProtobufTestBasic::TestAllTypes',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -541,7 +541,7 @@

our $_FOREIGNMESSAGE = Protobuf::Descriptor->new(
name => 'ForeignMessage',
- full_name => 'protobuf_unittest.ForeignMessage',
+ full_name => 'ProtobufTestBasic::ForeignMessage',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -563,7 +563,7 @@

our $_TESTREQUIRED = Protobuf::Descriptor->new(
name => 'TestRequired',
- full_name => 'protobuf_unittest.TestRequired',
+ full_name => 'ProtobufTestBasic::TestRequired',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -777,7 +777,7 @@

our $_TESTREQUIREDFOREIGN = Protobuf::Descriptor->new(
name => 'TestRequiredForeign',
- full_name => 'protobuf_unittest.TestRequiredForeign',
+ full_name => 'ProtobufTestBasic::TestRequiredForeign',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -811,7 +811,7 @@

our $_TESTFOREIGNNESTED = Protobuf::Descriptor->new(
name => 'TestForeignNested',
- full_name => 'protobuf_unittest.TestForeignNested',
+ full_name => 'ProtobufTestBasic::TestForeignNested',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -833,7 +833,7 @@

our $_TESTEMPTYMESSAGE = Protobuf::Descriptor->new(
name => 'TestEmptyMessage',
- full_name => 'protobuf_unittest.TestEmptyMessage',
+ full_name => 'ProtobufTestBasic::TestEmptyMessage',
containing_type => undef,
fields => [
],
@@ -849,7 +849,7 @@

our $_TESTREALLYLARGETAGNUMBER = Protobuf::Descriptor->new(
name => 'TestReallyLargeTagNumber',
- full_name => 'protobuf_unittest.TestReallyLargeTagNumber',
+ full_name => 'ProtobufTestBasic::TestReallyLargeTagNumber',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -877,7 +877,7 @@

our $_TESTRECURSIVEMESSAGE = Protobuf::Descriptor->new(
name => 'TestRecursiveMessage',
- full_name => 'protobuf_unittest.TestRecursiveMessage',
+ full_name => 'ProtobufTestBasic::TestRecursiveMessage',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -905,7 +905,7 @@

our $_TESTMUTUALRECURSIONA = Protobuf::Descriptor->new(
name => 'TestMutualRecursionA',
- full_name => 'protobuf_unittest.TestMutualRecursionA',
+ full_name => 'ProtobufTestBasic::TestMutualRecursionA',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -927,7 +927,7 @@

our $_TESTMUTUALRECURSIONB = Protobuf::Descriptor->new(
name => 'TestMutualRecursionB',
- full_name => 'protobuf_unittest.TestMutualRecursionB',
+ full_name => 'ProtobufTestBasic::TestMutualRecursionB',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -955,7 +955,7 @@

our $_TESTDUPFIELDNUMBER_FOO = Protobuf::Descriptor->new(
name => 'Foo',
- full_name => 'protobuf_unittest.TestDupFieldNumber.Foo',
+ full_name => 'ProtobufTestBasic::TestDupFieldNumber.Foo',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -976,7 +976,7 @@

our $_TESTDUPFIELDNUMBER_BAR = Protobuf::Descriptor->new(
name => 'Bar',
- full_name => 'protobuf_unittest.TestDupFieldNumber.Bar',
+ full_name => 'ProtobufTestBasic::TestDupFieldNumber.Bar',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -997,7 +997,7 @@

our $_TESTDUPFIELDNUMBER = Protobuf::Descriptor->new(
name => 'TestDupFieldNumber',
- full_name => 'protobuf_unittest.TestDupFieldNumber',
+ full_name => 'ProtobufTestBasic::TestDupFieldNumber',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -1031,7 +1031,7 @@

our $_TESTNESTEDMESSAGEHASBITS_NESTEDMESSAGE = Protobuf::Descriptor->new(
name => 'NestedMessage',
- full_name => 'protobuf_unittest.TestNestedMessageHasBits.NestedMessage',
+ full_name => 'ProtobufTestBasic::TestNestedMessageHasBits.NestedMessage',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -1058,7 +1058,7 @@

our $_TESTNESTEDMESSAGEHASBITS = Protobuf::Descriptor->new(
name => 'TestNestedMessageHasBits',
- full_name => 'protobuf_unittest.TestNestedMessageHasBits',
+ full_name => 'ProtobufTestBasic::TestNestedMessageHasBits',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -1080,7 +1080,7 @@

our $_TESTCAMELCASEFIELDNAMES = Protobuf::Descriptor->new(
name => 'TestCamelCaseFieldNames',
- full_name => 'protobuf_unittest.TestCamelCaseFieldNames',
+ full_name => 'ProtobufTestBasic::TestCamelCaseFieldNames',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -1168,7 +1168,7 @@

our $_TESTFIELDORDERINGS = Protobuf::Descriptor->new(
name => 'TestFieldOrderings',
- full_name => 'protobuf_unittest.TestFieldOrderings',
+ full_name => 'ProtobufTestBasic::TestFieldOrderings',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -1202,7 +1202,7 @@

our $_TESTEXTREMEDEFAULTVALUES = Protobuf::Descriptor->new(
name => 'TestExtremeDefaultValues',
- full_name => 'protobuf_unittest.TestExtremeDefaultValues',
+ full_name => 'ProtobufTestBasic::TestExtremeDefaultValues',
containing_type => undef,
fields => [
Protobuf::FieldDescriptor->new(
@@ -1254,7 +1254,7 @@

our $_FOOREQUEST = Protobuf::Descriptor->new(
name => 'FooRequest',
- full_name => 'protobuf_unittest.FooRequest',
+ full_name => 'ProtobufTestBasic::FooRequest',
containing_type => undef,
fields => [
],
@@ -1270,7 +1270,7 @@

our $_FOORESPONSE = Protobuf::Descriptor->new(
name => 'FooResponse',
- full_name => 'protobuf_unittest.FooResponse',
+ full_name => 'ProtobufTestBasic::FooResponse',
containing_type => undef,
fields => [
],
@@ -1286,7 +1286,7 @@

our $_BARREQUEST = Protobuf::Descriptor->new(
name => 'BarRequest',
- full_name => 'protobuf_unittest.BarRequest',
+ full_name => 'ProtobufTestBasic::BarRequest',
containing_type => undef,
fields => [
],
@@ -1302,7 +1302,7 @@

our $_BARRESPONSE = Protobuf::Descriptor->new(
name => 'BarResponse',
- full_name => 'protobuf_unittest.BarResponse',
+ full_name => 'ProtobufTestBasic::BarResponse',
containing_type => undef,
fields => [
],
@@ -1392,3 +1392,5 @@

## Fix foreign fields in extensions:
## Services:
+
+1;

Modified: trunk/perl/t/descriptors.t
==============================================================================
--- trunk/perl/t/descriptors.t (original)
+++ trunk/perl/t/descriptors.t Thu Sep 25 10:55:49 2008
@@ -8,19 +8,19 @@

my $enum = Protobuf::EnumDescriptor->new(
name => 'ErrorCode',
- fullname => "Foo.NewCode",
- );
+ full_name => "Foo.NewCode",
+);

ok($enum);
is($enum->name, "ErrorCode");
$enum->set_name("NewCode");
is($enum->name, "NewCode");

-is($enum->fullname, "Foo.NewCode");
+is($enum->full_name, "Foo.NewCode");

my $field = Protobuf::FieldDescriptor->new(
- name => "Name",
- fullname => "Foo.NewName",
+ name => "Name",
+ full_name => "Foo.NewName",
type => TYPE_STRING,
);

@@ -31,8 +31,8 @@
is($enum->name, "NewCode");

my $attr = Moose::Meta::Attribute->interpolate_class_and_new( blah =>
- traits => [qw(Protobuf::Field::Scalar)],
- field => $field,
+ traits => [qw(Protobuf::Field::Scalar)],
+ field => $field,
);

isa_ok( $attr, "Moose::Meta::Attribute" );

Modified: trunk/protobuf/src/google/protobuf/compiler/perl/perl_generator.cc
==============================================================================
--- trunk/protobuf/src/google/protobuf/compiler/perl/perl_generator.cc
(original)
+++ trunk/protobuf/src/google/protobuf/compiler/perl/perl_generator.cc Thu
Sep 25 10:55:49 2008
@@ -304,8 +304,11 @@
"package_name", package_name);

if (file->options().has_perl_message_package()) {
- printer_->Print("package `package_name`;\n\n",
- "package_name",
file->options().perl_message_package());
+ string message_package_name = file->options().perl_message_package();
+ if (message_package_name != package_name) {
+ printer_->Print("package `package_name`;\n\n",
+ "package_name",
file->options().perl_message_package());
+ }
}

printer_->Print("\n"
@@ -336,6 +339,7 @@
FixForeignFieldsInExtensions();
printer_->Print("## Services:\n");
PrintServices();
+ printer_->Print("\n1;\n");
return !printer.failed();
}

@@ -352,25 +356,11 @@
// Prints descriptors and module-level constants for all top-level
// enums defined in |file|.
void Generator::PrintTopLevelEnums() const {
- vector<pair<string, int> > top_level_enum_values;
for (int i = 0; i < file_->enum_type_count(); ++i) {
const EnumDescriptor& enum_descriptor = *file_->enum_type(i);
PrintEnum(enum_descriptor);
printer_->Print("\n");
-
- for (int j = 0; j < enum_descriptor.value_count(); ++j) {
- const EnumValueDescriptor& value_descriptor =
*enum_descriptor.value(j);
- top_level_enum_values.push_back(
- make_pair(value_descriptor.name(), value_descriptor.number()));
- }
- }
-
- for (int i = 0; i < top_level_enum_values.size(); ++i) {
- printer_->Print("`name` = `value`;\n",
- "name", top_level_enum_values[i].first,
- "value", SimpleItoa(top_level_enum_values[i].second));
}
- printer_->Print("\n");
}

// Prints all enums contained in all message types in |file|.
@@ -387,7 +377,12 @@
map<string, string> m;
m["descriptor_name"] = ModuleLevelDescriptorName(enum_descriptor);
m["name"] = enum_descriptor.name();
- m["full_name"] = enum_descriptor.full_name();
+ if (enum_descriptor.file()->options().has_perl_message_package()) {
+ m["full_name"] =
enum_descriptor.file()->options().perl_message_package()
+ + "::" + enum_descriptor.name();
+ } else {
+ m["full_name"] = enum_descriptor.full_name();
+ }
m["filename"] = enum_descriptor.name();
const char enum_descriptor_template[] =
"our $`descriptor_name` = Protobuf::EnumDescriptor->new(\n"
@@ -471,7 +466,12 @@
printer_->Indent();
map<string, string> m;
m["name"] = message_descriptor.name();
- m["full_name"] = message_descriptor.full_name();
+ if (message_descriptor.file()->options().has_perl_message_package()) {
+ m["full_name"] =
message_descriptor.file()->options().perl_message_package()
+ + "::" + ModuleLevelMessageName(message_descriptor);
+ } else {
+ m["full_name"] = message_descriptor.full_name();
+ }
m["filename"] = message_descriptor.file()->name();
const char required_function_arguments[] =
"name => '`name`',\n"
@@ -526,7 +526,7 @@
// to output a Perl version of the descriptors, which the metaclass in
// Message.pm will use to construct the meat of the class itself.
//
-// Mutually recursive with PrintNestedMessages().
+// Recursive.
void Generator::PrintMessage(
const string& class_prefix,
const Descriptor& message_descriptor) const {
@@ -659,7 +659,7 @@
extension_field,
"extensions_by_name");
printer_->Print(m,
- "#
`extended_message_class`->RegisterExtension(`$field`);\n");
+ "#
`extended_message_class`->RegisterExtension($`field`);\n");
}

void Generator::FixForeignFieldsInNestedExtensions(

Modified: trunk/protobuf/src/google/protobuf/descriptor.proto
==============================================================================
--- trunk/protobuf/src/google/protobuf/descriptor.proto (original)
+++ trunk/protobuf/src/google/protobuf/descriptor.proto Thu Sep 25 10:55:49
2008
@@ -206,13 +206,14 @@
// top-level extensions defined in the file.
optional bool java_multiple_files = 10 [default=false];

- // If set to "Foo::Bar", "Foo/Bar.pm" will be generated.
+ // Specifies Perl file to generate as a Perl package, e.g. if set to
+ // "Foo::Bletch" the Perl file will be Foo/Bletch.pm.
optional string perl_file_package = 11;

- // If set, all messages will be prefixed with this package name.
- // Don't include "::" at the end. If set to "Foo::Bar", message
- // "Baz" will be in package "Foo::Bar::Baz" (in file Foo/Bar.pm if
- // the option 'perl_file_package' above is set to "Foo::Bar")
+ // If set, all messages will be prefixed with this package name in the
+ // Perl generated code. Don't include "::" at the end. If set
to "Foo::Bar",
+ // message "Baz" will be in package "Foo::Bar::Baz" (in file
Foo/Bletch.pm if
+ // the option 'perl_file_package' above is set to "Foo::Bletch")
optional string perl_message_package = 12;

// Generated classes can be optimized for speed or code size.

Reply all
Reply to author
Forward
0 new messages