File Coverage

blib/lib/MooseX/FunkyAttributes.pm
Criterion Covered Total %
statement 23 23 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod n/a
total 31 31 100.0


line stmt bran cond sub pod time code
1             package MooseX::FunkyAttributes;
2              
3 6     6   3228716 use 5.008;
  6         25  
  6         313  
4 6     6   35 use strict;
  6         12  
  6         211  
5 6     6   37 use warnings;
  6         16  
  6         354  
6              
7             BEGIN {
8 6     6   15 $MooseX::FunkyAttributes::AUTHORITY = 'cpan:TOBYINK';
9 6         336 $MooseX::FunkyAttributes::VERSION = '0.003';
10             }
11              
12 6         50 use Exporter::Shiny our(@EXPORT) = qw(
13             FunkyAttribute
14             InsideOutAttribute
15             DelegatedAttribute
16 6     6   5605 );
  6         30069  
17              
18 6         37 use aliased qw(
19             MooseX::FunkyAttributes::Role::Attribute
20             FunkyAttribute
21 6     6   20089 );
  6         5137  
22              
23 6         37 use aliased qw(
24             MooseX::FunkyAttributes::Role::Attribute::InsideOut
25             InsideOutAttribute
26 6     6   793 );
  6         11  
27              
28 6         39 use aliased qw(
29             MooseX::FunkyAttributes::Role::Attribute::Delegated
30             DelegatedAttribute
31 6     6   715 );
  6         25  
32              
33             1;
34              
35             __END__
36              
37             =head1 NAME
38              
39             MooseX::FunkyAttributes - add code smell to your Moose attributes
40              
41             =head1 SYNOPSIS
42              
43             package Circle;
44            
45             use Moose;
46             use MooseX::FunkyAttributes;
47            
48             has radius => (
49             is => 'rw',
50             isa => 'Num',
51             predicate => 'has_radius',
52             );
53            
54             has diameter => (
55             traits => [ FunkyAttribute ],
56             is => 'rw',
57             isa => 'Num',
58             custom_get => sub { 2 * $_->radius },
59             custom_set => sub { $_->radius( $_[-1] / 2 ) },
60             custom_has => sub { $_->has_radius },
61             );
62              
63             =head1 DESCRIPTION
64              
65             The MooseX::FunkyAttributes module itself just provides some convenience
66             functions for the attribute traits that are distributed with it.
67              
68             The grand uniting idea behind the traits is that although Moose generally
69             uses blessed hashrefs for object internals, storing each attribute as an
70             entry in the hash, sometimes you may want to change that behaviour for
71             individual attributes. For example, you could use the inside-out technique
72             for one attribute to suppress it from appearing in L<Data::Dumper> dumps.
73              
74             The traits bundled with MooseX::FunkyAttributes are as follows. Please
75             see the documentation for each individual trait for further details.
76              
77             =over
78              
79             =item * L<MooseX::FunkyAttributes::Role::Attribute>
80              
81             Allows you to override the get, set, clear and predicate operations for an
82             attribute. These are just the raw operations you're overriding; you do not
83             need to implement type constraint checking, coercians, checking required
84             attributes, defaults, builders, etc.
85              
86             With this trait you can create attributes which are calculated on the fly
87             (as in the SYNOPSIS) or stored somewhere outside the object's blessed
88             hashref.
89              
90             =item * L<MooseX::FunkyAttributes::Role::Attribute::InsideOut>
91              
92             This trait stores the attribute using the inside-out technique. If you want
93             your whole object to be inside-out, then use L<MooseX::InsideOut>.
94              
95             =item * L<MooseX::FunkyAttributes::Role::Attribute::Delegated>
96              
97             This trait delegates the storage of one attribute to another attribute.
98             For example:
99              
100             package Head;
101             use Moose;
102             has mouth => (
103             is => 'ro',
104             isa => 'Mouth',
105             );
106            
107             package Person;
108             use Moose;
109             use MooseX::FunkyAttributes;
110             has head => (
111             is => 'ro',
112             isa => 'Head',
113             );
114             has mouth => (
115             is => 'ro',
116             isa => 'Mouth::Human',
117             traits => [ DelegatedAttribute ],
118             delegated_to => 'head',
119             );
120              
121             It is not dissimilar to the Moose's idea of "handles" (in the example above,
122             we could have not defined a C<mouth> attribute as part of the C<Person> class,
123             and just specified that C<head> handles C<mouth>) however because C<mouth>
124             is now a proper attribute in the Person class (and will show up via Moose's
125             introspection API), it can have its own type constraints, coercion, trigger,
126             predicate, etc.
127              
128             =back
129              
130             The MooseX::FunkyAttributes module itself exports some constants (e.g.
131             C<FunkyAttribute> in the SYNOPSIS) which can be used as abbreviations for
132             the full trait package names. These constants are:
133              
134             =over
135              
136             =item C<FunkyAttribute>
137              
138             =item C<InsideOutAttribute>
139              
140             =item C<DelegatedAttribute>
141              
142             =back
143              
144             =head1 BUGS
145              
146             Please report any bugs to
147             L<http://rt.cpan.org/Dist/Display.html?Queue=MooseX-FunkyAttributes>.
148              
149             =head1 SEE ALSO
150              
151             L<MooseX::FunkyAttributes::Role::Attribute>,
152             L<MooseX::FunkyAttributes::Role::Attribute::InsideOut>,
153             L<MooseX::FunkyAttributes::Role::Attribute::Delegated>.
154              
155             These effect storage for whole object instances; not just one attribute:
156             L<MooseX::GlobRef>,
157             L<MooseX::InsideOut>,
158             L<MooseX::ArrayRef>.
159              
160             L<MooseX::CustomInitArgs> - if you have (as in the SYNOPSIS) one attribute
161             which is calculated from another (diameter from radius), MooseX::CustomInitArgs
162             will allow you to accept both attributes in the constructor (i.e. accept a
163             diameter in the constructor, halve it, and set the radius attribute).
164              
165             =head1 AUTHOR
166              
167             Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
168              
169             =head1 COPYRIGHT AND LICENCE
170              
171             This software is copyright (c) 2012-2014 by Toby Inkster.
172              
173             This is free software; you can redistribute it and/or modify it under
174             the same terms as the Perl 5 programming language system itself.
175              
176             =head1 DISCLAIMER OF WARRANTIES
177              
178             THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
179             WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
180             MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
181