Commit | Line | Data |
63fcc508 |
1 | package MooseX::ClassAttribute::Trait::Role; |
88b7f2c8 |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use MooseX::ClassAttribute::Meta::Role::Attribute; |
7 | use Scalar::Util qw( blessed ); |
8 | |
9 | use namespace::autoclean; |
10 | use Moose::Role; |
11 | |
63fcc508 |
12 | with 'MooseX::ClassAttribute::Trait::Mixin::HasClassAttributes'; |
88b7f2c8 |
13 | |
14 | around add_class_attribute => sub { |
15 | my $orig = shift; |
16 | my $self = shift; |
17 | my $attr = ( |
18 | blessed $_[0] && $_[0]->isa('Class::MOP::Mixin::AttributeCore') |
19 | ? $_[0] |
20 | : MooseX::ClassAttribute::Meta::Role::Attribute->new(@_) |
21 | ); |
22 | |
23 | $self->$orig($attr); |
24 | |
25 | return $attr; |
26 | }; |
27 | |
28 | sub _attach_class_attribute { |
29 | my ( $self, $attribute ) = @_; |
30 | |
31 | $attribute->attach_to_role($self); |
32 | } |
33 | |
34 | 1; |
35 | |
36 | __END__ |
37 | |
38 | =pod |
39 | |
40 | =head1 NAME |
41 | |
63fcc508 |
42 | MooseX::ClassAttribute::Trait::Class - A metaclass role for classes with class attributes |
88b7f2c8 |
43 | |
44 | =head1 SYNOPSIS |
45 | |
46 | for my $attr ( HasClassAttributes->meta()->get_all_class_attributes() ) |
47 | { |
48 | print $attr->name(); |
49 | } |
50 | |
51 | =head1 DESCRIPTION |
52 | |
53 | This role adds awareness of class attributes to a metaclass object. It |
54 | provides a set of introspection methods that largely parallel the |
55 | existing attribute methods, except they operate on class attributes. |
56 | |
57 | =head1 METHODS |
58 | |
59 | Every method provided by this role has an analogous method in |
60 | C<Class::MOP::Class> or C<Moose::Meta::Class> for regular attributes. |
61 | |
62 | =head2 $meta->has_class_attribute($name) |
63 | |
64 | =head2 $meta->get_class_attribute($name) |
65 | |
66 | =head2 $meta->get_class_attribute_list() |
67 | |
68 | =head2 $meta->get_class_attribute_map() |
69 | |
70 | These methods operate on the current metaclass only. |
71 | |
72 | =head2 $meta->add_class_attribute(...) |
73 | |
74 | This accepts the same options as the L<Moose::Meta::Attribute> |
75 | C<add_attribute()> method. However, if an attribute is specified as |
76 | "required" an error will be thrown. |
77 | |
78 | =head2 $meta->remove_class_attribute($name) |
79 | |
80 | If the named class attribute exists, it is removed from the class, |
81 | along with its accessor methods. |
82 | |
83 | =head2 $meta->get_all_class_attributes() |
84 | |
85 | This method returns a list of attribute objects for the class and all |
86 | its parent classes. |
87 | |
88 | =head2 $meta->find_class_attribute_by_name($name) |
89 | |
90 | This method looks at the class and all its parent classes for the |
91 | named class attribute. |
92 | |
93 | =head2 $meta->get_class_attribute_value($name) |
94 | |
95 | =head2 $meta->set_class_attribute_value($name, $value) |
96 | |
97 | =head2 $meta->set_class_attribute_value($name) |
98 | |
99 | =head2 $meta->clear_class_attribute_value($name) |
100 | |
101 | These methods operate on the storage for class attribute values, which |
102 | is attached to the metaclass object. |
103 | |
104 | There's really no good reason for you to call these methods unless |
105 | you're doing some deep hacking. They are named as public methods |
106 | solely because they are used by other meta roles and classes in this |
107 | distribution. |
108 | |
109 | =head2 inline_class_slot_access($name) |
110 | |
111 | =head2 inline_get_class_slot_value($name) |
112 | |
113 | =head2 inline_set_class_slot_value($name, $val_name) |
114 | |
115 | =head2 inline_is_class_slot_initialized($name) |
116 | |
117 | =head2 inline_deinitialize_class_slot($name) |
118 | |
119 | =head2 inline_weaken_class_slot_value($name) |
120 | |
121 | These methods return code snippets for inlining. |
122 | |
123 | There's really no good reason for you to call these methods unless |
124 | you're doing some deep hacking. They are named as public methods |
125 | solely because they are used by other meta roles and classes in this |
126 | distribution. |
127 | |
128 | =head1 AUTHOR |
129 | |
130 | Dave Rolsky, C<< <autarch@urth.org> >> |
131 | |
132 | =head1 BUGS |
133 | |
134 | See L<MooseX::ClassAttribute> for details. |
135 | |
136 | =head1 COPYRIGHT & LICENSE |
137 | |
138 | Copyright 2007-2008 Dave Rolsky, All Rights Reserved. |
139 | |
140 | This program is free software; you can redistribute it and/or modify |
141 | it under the same terms as Perl itself. |
142 | |
143 | =cut |