| 1 | package MooseX::Attribute::Prototype::Object; | ||
| 2 | |||
| 3 | use Moose; | ||
| 4 | our $VERSION = '0.10'; | ||
| 5 | our $AUTHORITY = 'cpan:CTBROWN'; | ||
| 6 | |||
| 7 | has 'name' => ( | ||
| 8 | is => 'rw' , #rw | ||
| 9 | isa => 'Str' , | ||
| 10 | required => 1 , | ||
| 11 | documentation => 'Name for atttribute prototype: [$role/$attribute]' , | ||
| 12 | trigger => | ||
| 13 | sub { | ||
| 14 | my ( $self, $val, $meta ) = @_; | ||
| 15 | |||
| 16 | if ( $val =~ /\// ) { # prototype => MyRole/my_attr: | ||
| 17 | $val =~ m/(.*)\/(.*)/; | ||
| 18 | |||
| 19 | $self->role( $1 ) ; | ||
| 20 | $self->attribute( $2 ); | ||
| 21 | |||
| 22 | } else { # prototype => MyRole equivalent to MyRole/myrole | ||
| 23 | |||
| 24 | $self->role($val); | ||
| 25 | $val =~ s/.*:://; | ||
| 26 | $self->attribute( lc($val) ); | ||
| 27 | |||
| 28 | } | ||
| 29 | |||
| 30 | } | ||
| 31 | ); | ||
| 32 | |||
| 33 | |||
| 34 | |||
| 35 | has 'role' => ( | ||
| 36 | is => 'rw' , | ||
| 37 | isa => 'Str' , | ||
| 38 | required => 0 , | ||
| 39 | lazy_build => 1 , | ||
| 40 | documentation => "Role name of the Prototype role" , | ||
| 41 | ); | ||
| 42 | |||
| 43 | sub _build_role { | ||
| 44 | |||
| 45 | my $name = $_[0]->name; | ||
| 46 | my $role; | ||
| 47 | |||
| 48 | $name =~ m/(^.*)::(.*$)/; | ||
| 49 | |||
| 50 | if ( $name =~ /\// ) { | ||
| 51 | $name =~ m/(.*)\/(.*)/; | ||
| 52 | $role = $1; | ||
| 53 | } else { | ||
| 54 | $name =~ s/.*:://; | ||
| 55 | $role = $name; | ||
| 56 | } | ||
| 57 | |||
| 58 | return $role; | ||
| 59 | |||
| 60 | } | ||
| 61 | |||
| 62 | |||
| 63 | has 'attribute' => ( | ||
| 64 | is => 'rw' , | ||
| 65 | isa => 'Str' , | ||
| 66 | required => 0 , | ||
| 67 | lazy_build => 1 , | ||
| 68 | documentation => "Attribute name from prototype role." , | ||
| 69 | ); | ||
| 70 | |||
| 71 | sub _build_attribute { | ||
| 72 | |||
| 73 | my $name = $_[0]->name; | ||
| 74 | my $attribute; | ||
| 75 | |||
| 76 | if ( $_->name =~ /\// ) { | ||
| 77 | $_[0]->name =~ m/(.*)\/(.*)/; | ||
| 78 | $attribute = $2; | ||
| 79 | } else { | ||
| 80 | $name =~ s/.*:://; | ||
| 81 | $attribute = $name; | ||
| 82 | } | ||
| 83 | |||
| 84 | return $attribute; | ||
| 85 | |||
| 86 | } | ||
| 87 | |||
| 88 | |||
| 89 | has 'options' => ( | ||
| 90 | is => 'rw' , | ||
| 91 | isa => 'HashRef' , | ||
| 92 | required => 1 , | ||
| 93 | default => sub { {} } , | ||
| 94 | documentation => "The options specifications for the attribute" , | ||
| 95 | ); | ||
| 96 | |||
| 97 | has 'referenced' => ( | ||
| 98 | is => 'rw' , | ||
| 99 | isa => 'Bool' , | ||
| 100 | required => 1 , | ||
| 101 | default => 0 , | ||
| 102 | documentation => "Indicates if the attibute has been referenced as a prototype" , | ||
| 103 | ); | ||
| 104 | |||
| 105 | sub get_prototype_options { | ||
| 106 | return $_[0]->options; | ||
| 107 | } | ||
| 108 | |||
| 109 | no Moose; | ||
| 110 | |||
| 111 | =pod | ||
| 112 | |||
| 113 | =head1 NAME | ||
| 114 | |||
| 115 | MooseX::Attribute::Prototype::Object - Attribute Prototype Class | ||
| 116 | |||
| 117 | =head1 VERSION | ||
| 118 | |||
| 119 | 0.10 - released 2009-07-18 | ||
| 120 | |||
| 121 | =head1 SYNOPSIS | ||
| 122 | |||
| 123 | use MooseX::Attribute::Prototype::Object; | ||
| 124 | |||
| 125 | my $proto = MooseX::Attribute::Prototype::Object->new( | ||
| 126 | name => 'MooseX::Foo/bar' , # The 'bar' attribute from MooseX::Foo.pm | ||
| 127 | ); | ||
| 128 | |||
| 129 | # -OR- | ||
| 130 | |||
| 131 | my $proto = MooseX::Attribute::Prototype::Object->new( | ||
| 132 | name => 'MooseX::Foo' , # The 'foo' attribute the MooseX::Foo.pm | ||
| 133 | }; | ||
| 134 | |||
| 135 | |||
| 136 | =head1 DESCRIPTION | ||
| 137 | |||
| 138 | This class is use internally by L<MooseX::Attribute::Prototype> | ||
| 139 | to manage the specifications for prototype attributes. | ||
| 140 | |||
| 141 | This module provides an attribute prototype class, | ||
| 142 | L<MooseX::Attribute::Prototype::Object> that holds all of the user | ||
| 143 | specification for an attribute without actually installing the | ||
| 144 | attribute. Later, the prototype can provide defaults for other attributes. | ||
| 145 | |||
| 146 | =head1 Attributes | ||
| 147 | |||
| 148 | =head2 name (required) | ||
| 149 | |||
| 150 | The name for the attribute prototype in the form of C<Role/attribute> or | ||
| 151 | simply C<role>. In the later case, attribute used a prototype the name of the | ||
| 152 | module file in lower case without the C<.pm> suffix. | ||
| 153 | |||
| 154 | =head2 role | ||
| 155 | |||
| 156 | The role in which the prototype attribute lives. This is automatically set. | ||
| 157 | |||
| 158 | =head2 attribute | ||
| 159 | |||
| 160 | The name of the attribute for the prototype. This is automatically set. | ||
| 161 | |||
| 162 | =head2 options | ||
| 163 | |||
| 164 | The specifications for the attribute. This is automatically set. | ||
| 165 | |||
| 166 | =head2 referenced | ||
| 167 | |||
| 168 | =head1 SEE ALSO | ||
| 169 | |||
| 170 | L<MooseX::Attribute::Prototype>, | ||
| 171 | |||
| 172 | L<MooseX::Attribute::Prototype::Object>, | ||
| 173 | |||
| 174 | L<MooseX::Attribute::Prototype::Collection>, | ||
| 175 | |||
| 176 | L<Moose> | ||
| 177 | |||
| 178 | |||
| 179 | =head1 AUTHOR | ||
| 180 | |||
| 181 | Christopher Brown, C<< <ctbrown at cpan.org> >> | ||
| 182 | |||
| 183 | =head1 BUGS | ||
| 184 | |||
| 185 | Please report any bugs or feature requests to C<bug-moosex-attribute at rt.cpan.org>, or through | ||
| 186 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=MooseX-Attribute-Prototpye>. I will be notified, and then you'll | ||
| 187 | automatically be notified of progress on your bug as I make changes. | ||
| 188 | |||
| 189 | |||
| 190 | =head1 SUPPORT | ||
| 191 | |||
| 192 | You can find documentation for this module with the perldoc command. | ||
| 193 | |||
| 194 | perldoc MooseX::Attribute::Prototype | ||
| 195 | |||
| 196 | You can also look for information at: | ||
| 197 | |||
| 198 | =over 4 | ||
| 199 | |||
| 200 | =item * RT: CPAN's request tracker | ||
| 201 | |||
| 202 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=MooseX-Attribute-Prototype> | ||
| 203 | |||
| 204 | =item * AnnoCPAN: Annotated CPAN documentation | ||
| 205 | |||
| 206 | L<http://annocpan.org/dist/MooseX-Attribute-Prototype> | ||
| 207 | |||
| 208 | =item * CPAN Ratings | ||
| 209 | |||
| 210 | L<http://cpanratings.perl.org/d/MooseX-Attribute-Prototype> | ||
| 211 | |||
| 212 | =item * Search CPAN | ||
| 213 | |||
| 214 | L<http://search.cpan.org/dist/MooseX-Attribute-Prototype> | ||
| 215 | |||
| 216 | =back | ||
| 217 | |||
| 218 | |||
| 219 | =head1 ACKNOWLEDGEMENTS | ||
| 220 | |||
| 221 | Though they would probably cringe to hear it, this effort would not have | ||
| 222 | been possible without: | ||
| 223 | |||
| 224 | Shawn Moore | ||
| 225 | |||
| 226 | David Rolsky | ||
| 227 | |||
| 228 | Thomas Doran | ||
| 229 | |||
| 230 | Stevan Little | ||
| 231 | |||
| 232 | |||
| 233 | =head1 COPYRIGHT & LICENSE | ||
| 234 | |||
| 235 | Copyright 2009 Christopher Brown and Open Data Group L<http://opendatagroup.com>, | ||
| 236 | all rights reserved. | ||
| 237 | |||
| 238 | This program is free software; you can redistribute it and/or modify it | ||
| 239 | under the same terms as Perl itself. | ||
| 240 | |||
| 241 | |||
| 242 | =cut | ||
| 243 | |||
| 244 | 1; # End of module MooseX::Attribute::Prototype::Object |