X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FClassData.pm;h=fd6cd82e04bcb1fe63d15ff4cc2dc04d9e81aee1;hp=6b14d7ef9988bfe0436a883cf19e6ff7b830fb26;hb=536bee890cf24e0e4bcda7562e7b70cc03ca0620;hpb=df3ea11bb1ad740663f2a4c909fba71612aa6a48 diff --git a/lib/Catalyst/ClassData.pm b/lib/Catalyst/ClassData.pm index 6b14d7e..fd6cd82 100644 --- a/lib/Catalyst/ClassData.pm +++ b/lib/Catalyst/ClassData.pm @@ -1,9 +1,9 @@ package Catalyst::ClassData; use Moose::Role; +use Moose::Meta::Class (); use Class::MOP; -use Class::MOP::Object; -use Scalar::Util 'blessed'; +use Moose::Util (); sub mk_classdata { my ($class, $attribute) = @_; @@ -13,8 +13,9 @@ sub mk_classdata { my $slot = '$'.$attribute; my $accessor = sub { my $pkg = ref $_[0] || $_[0]; - my $meta = $pkg->Class::MOP::Object::meta(); - if (@_ > 1){ + my $meta = Moose::Util::find_meta($pkg) + || Moose::Meta::Class->initialize( $pkg ); + if (@_ > 1) { $meta->namespace->{$attribute} = \$_[1]; return $_[1]; } @@ -29,14 +30,6 @@ sub mk_classdata { return ${$v}; } else { foreach my $super ( $meta->linearized_isa ) { - # If there is a code symbol for this attr in a parent class, - # then copy it into our package. Is this the correct - # fix for C::D::I back-compat? (t0m) - my $parent_symbol = *{"${super}::${attribute}"}{CODE} ? \&{"${super}::${attribute}"} : undef; - # FIXME - this is over-enthusiastic? - if (defined $parent_symbol) { - *{"${pkg}::${attribute}"} = $parent_symbol; - } # tighter version of same after # my $super_meta = Moose::Meta::Class->initialize($super); my $v = ${"${super}::"}{$attribute} ? *{"${super}::${attribute}"}{SCALAR} : undef; @@ -52,17 +45,18 @@ sub mk_classdata { unless ref $accessor eq 'CODE'; my $meta = $class->Class::MOP::Object::meta(); - my $immutable_options; - if( $meta->is_immutable ){ - $immutable_options = $meta->get_immutable_options; - $meta->make_mutable; - } + confess "${class}'s metaclass is not a Class::MOP::Class" + unless $meta->isa('Class::MOP::Class'); + + my $was_immutable = $meta->is_immutable; + $meta->make_mutable if $was_immutable; + my $alias = "_${attribute}_accessor"; $meta->add_method($alias, $accessor); $meta->add_method($attribute, $accessor); - if(defined $immutable_options){ - $meta->make_immutable(%{ $immutable_options }); - } + + $meta->make_immutable if $was_immutable; + $class->$attribute($_[2]) if(@_ > 2); return $accessor; } @@ -74,7 +68,7 @@ __END__ =head1 NAME -Catalyst::ClassData - Class data acessors +Catalyst::ClassData - Class data accessors =head1 METHODS @@ -89,7 +83,7 @@ Guillermo Roditi =head1 COPYRIGHT -This program is free software, you can redistribute it and/or modify it under +This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself. =cut