X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FCatalyst%2FClassData.pm;h=154062a53c2d6d8980f2ebd1c3402d7c27d13e29;hb=3295c7dbc672a0d1c03f657a2a37f12f322bbece;hp=b4eecbef339d7ba612aafa43ecdbe97d6a2acbea;hpb=76aab9932e14205c81eeb31d811d2a131eede4cf;p=catagits%2FCatalyst-Runtime.git diff --git a/lib/Catalyst/ClassData.pm b/lib/Catalyst/ClassData.pm index b4eecbe..154062a 100644 --- a/lib/Catalyst/ClassData.pm +++ b/lib/Catalyst/ClassData.pm @@ -11,15 +11,29 @@ sub mk_classdata { my $slot = '$'.$attribute; my $accessor = sub { + my $meta = $_[0]->meta; + my $pkg = ref $_[0] || $_[0]; if(@_ > 1){ - $_[0]->meta->add_package_symbol($slot, \ $_[1]); + $meta->namespace->{$attribute} = \$_[1]; return $_[1]; } - foreach my $super ( (blessed $_[0] || $_[0]), $_[0]->meta->linearized_isa ) { - my $meta = Moose::Meta::Class->initialize($super); - if( $meta->has_package_symbol($slot) ){ - return ${ $meta->get_package_symbol($slot) }; + # tighter version of + # if ( $meta->has_package_symbol($slot) ) { + # return ${ $meta->get_package_symbol($slot) }; + # } + no strict 'refs'; + my $v = *{"${pkg}::${attribute}"}{SCALAR}; + if (defined ${$v}) { + return ${$v}; + } else { + foreach my $super ( $meta->linearized_isa ) { + # tighter version of same after + # my $super_meta = Moose::Meta::Class->initialize($super); + my $v = *{"${super}::${attribute}"}{SCALAR}; + if (defined ${$v}) { + return ${$v}; + } } } return; @@ -29,9 +43,17 @@ sub mk_classdata { unless ref $accessor eq 'CODE'; my $meta = $class->meta; + my $immutable_options; + if( $meta->is_immutable ){ + $immutable_options = $meta->get_immutable_options; + $meta->make_mutable; + } my $alias = "_${attribute}_accessor"; $meta->add_method($alias, $accessor); $meta->add_method($attribute, $accessor); + if(defined $immutable_options){ + $meta->make_immutable($immutable_options); + } $class->$attribute($_[2]) if(@_ > 2); return $accessor; } @@ -39,3 +61,26 @@ sub mk_classdata { 1; __END__ + + +=head1 NAME + +Catalyst::ClassData - Class data acessors + +=head1 METHODS + +=head2 mk_classdata $name, $optional_value + +A moose-safe clone of L that borrows some ideas from +L; + +=head1 AUTHOR + +Guillermo Roditi + +=head1 COPYRIGHT + +This program is free software, you can redistribute it and/or modify it under +the same terms as Perl itself. + +=cut