1 package Catalyst::ClassData;
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 = Moose::Util::find_meta($pkg)
16 || Moose->init_meta( for_class => $pkg );
18 $meta->namespace->{$attribute} = \$_[1];
23 # if ( $meta->has_package_symbol($slot) ) {
24 # return ${ $meta->get_package_symbol($slot) };
27 my $v = *{"${pkg}::${attribute}"}{SCALAR};
31 foreach my $super ( $meta->linearized_isa ) {
32 # tighter version of same after
33 # my $super_meta = Moose::Meta::Class->initialize($super);
34 my $v = ${"${super}::"}{$attribute} ? *{"${super}::${attribute}"}{SCALAR} : undef;
43 confess("Failed to create accessor: $@ ")
44 unless ref $accessor eq 'CODE';
46 my $meta = $class->Class::MOP::Object::meta();
47 confess "${class}'s metaclass is not a Class::MOP::Class"
48 unless $meta->isa('Class::MOP::Class');
50 my $was_immutable = $meta->is_immutable;
51 $meta->make_mutable if $was_immutable;
53 my $alias = "_${attribute}_accessor";
54 $meta->add_method($alias, $accessor);
55 $meta->add_method($attribute, $accessor);
57 $meta->make_immutable if $was_immutable;
59 $class->$attribute($_[2]) if(@_ > 2);
70 Catalyst::ClassData - Class data accessors
74 =head2 mk_classdata $name, $optional_value
76 A moose-safe clone of L<Class::Data::Inheritable> that borrows some ideas from
77 L<Class::Accessor::Grouped>;
85 This program is free software, you can redistribute it and/or modify it under
86 the same terms as Perl itself.