1 package Catalyst::ClassData;
4 use Moose::Meta::Class ();
9 my ($class, $attribute) = @_;
10 confess("mk_classdata() is a class method, not an object method")
13 my $slot = '$'.$attribute;
15 my $pkg = ref $_[0] || $_[0];
16 my $meta = Moose::Util::find_meta($pkg)
17 || Moose::Meta::Class->initialize( $pkg );
19 $meta->namespace->{$attribute} = \$_[1];
24 # if ( $meta->has_package_symbol($slot) ) {
25 # return ${ $meta->get_package_symbol($slot) };
28 my $v = *{"${pkg}::${attribute}"}{SCALAR};
32 foreach my $super ( $meta->linearized_isa ) {
33 # tighter version of same after
34 # my $super_meta = Moose::Meta::Class->initialize($super);
35 my $v = ${"${super}::"}{$attribute} ? *{"${super}::${attribute}"}{SCALAR} : undef;
44 confess("Failed to create accessor: $@ ")
45 unless ref $accessor eq 'CODE';
47 my $meta = $class->Class::MOP::Object::meta();
48 confess "${class}'s metaclass is not a Class::MOP::Class"
49 unless $meta->isa('Class::MOP::Class');
51 my $was_immutable = $meta->is_immutable;
52 $meta->make_mutable if $was_immutable;
54 my $alias = "_${attribute}_accessor";
55 $meta->add_method($alias, $accessor);
56 $meta->add_method($attribute, $accessor);
58 $meta->make_immutable if $was_immutable;
60 $class->$attribute($_[2]) if(@_ > 2);
71 Catalyst::ClassData - Class data accessors
75 =head2 mk_classdata $name, $optional_value
77 A moose-safe clone of L<Class::Data::Inheritable> that borrows some ideas from
78 L<Class::Accessor::Grouped>;
86 This library is free software. You can redistribute it and/or modify it under
87 the same terms as Perl itself.