[protobuf-perl commit] r158 - trunk/perl/lib/Protobuf/Attribute/Field

0 views
Skip to first unread message

codesite...@google.com

unread,
Jul 31, 2008, 7:49:52 PM7/31/08
to protobuf-p...@googlegroups.com
Author: nothi...@woobling.org
Date: Thu Jul 31 16:48:50 2008
New Revision: 158

Modified:
trunk/perl/lib/Protobuf/Attribute/Field/Scalar.pm

Log:
lazify default value for nested messages

Modified: trunk/perl/lib/Protobuf/Attribute/Field/Scalar.pm
==============================================================================
--- trunk/perl/lib/Protobuf/Attribute/Field/Scalar.pm (original)
+++ trunk/perl/lib/Protobuf/Attribute/Field/Scalar.pm Thu Jul 31
16:48:50 2008
@@ -19,13 +19,18 @@

my $type_constraint = $options->{type_constraint} = $class->field_to_type_constraint($options->{field});

+ #
if ( defined ( my $default = $field->default_value ) ) {
- $options->{lazy} = 1;
$options->{default} = $class->process_default($default, $type_constraint);
} elsif (
$type_constraint->isa("Moose::Meta::TypeConstraint::Class") ) {
my $class = $type_constraint->class;
$options->{default} = sub { $class->new }; # FIXME only ->isa("Protobuf::Message")?
}
+
+ # make sure predicate returns false even if we define a default.
the predicate
+ # should really check that the field has been set by something
other than the
+ # default
+ $options->{lazy} = 1 if exists $options->{default};

if ( $type_constraint->is_a_type_of("Math::BigInt") ) {
$options->{coerce} = 1;

Reply all
Reply to author
Forward
0 new messages