1 package Catalyst::ClassData;
5 use Class::MOP::Object;
8 my ($class, $attribute) = @_;
9 confess("mk_classdata() is a class method, not an object method")
12 my $slot = '$'.$attribute;
14 my $pkg = ref $_[0] || $_[0];
15 my $meta = $pkg->Class::MOP::Object::meta();
17 $meta->namespace->{$attribute} = \$_[1];
22 # if ( $meta->has_package_symbol($slot) ) {
23 # return ${ $meta->get_package_symbol($slot) };
26 my $v = *{"${pkg}::${attribute}"}{SCALAR};
30 foreach my $super ( $meta->linearized_isa ) {
31 # tighter version of same after
32 # my $super_meta = Moose::Meta::Class->initialize($super);
33 my $v = ${"${super}::"}{$attribute} ? *{"${super}::${attribute}"}{SCALAR} : undef;
42 confess("Failed to create accessor: $@ ")
43 unless ref $accessor eq 'CODE';
45 my $meta = $class->Class::MOP::Object::meta();
46 my $immutable_options;
47 if( $meta->is_immutable ){
48 $immutable_options = $meta->get_immutable_options;
51 my $alias = "_${attribute}_accessor";
52 $meta->add_method($alias, $accessor);
53 $meta->add_method($attribute, $accessor);
54 if(defined $immutable_options){
55 $meta->make_immutable(%{ $immutable_options });
57 $class->$attribute($_[2]) if(@_ > 2);
68 Catalyst::ClassData - Class data accessors
72 =head2 mk_classdata $name, $optional_value
74 A moose-safe clone of L<Class::Data::Inheritable> that borrows some ideas from
75 L<Class::Accessor::Grouped>;
83 This program is free software, you can redistribute it and/or modify it under
84 the same terms as Perl itself.