File Coverage

blib/lib/MooseX/ShortHas.pm
Criterion Covered Total %
statement 17 17 100.0
branch n/a
condition n/a
subroutine 6 6 100.0
pod n/a
total 23 23 100.0


line stmt bran cond sub pod time code
1              
2             use strictures 2;
3 2     2   1022412  
  2         27  
  2         86  
4             our $VERSION = '1.222491'; # VERSION
5              
6             # ABSTRACT: shortcuts for common Moose has attribute configurations
7              
8             #
9             # This file is part of MooseX-ShortHas
10             #
11             #
12             # Christian Walde has dedicated the work to the Commons by waiving all of his
13             # or her rights to the work worldwide under copyright law and all related or
14             # neighboring legal rights he or she had in the work, to the extent allowable by
15             # law.
16             #
17             # Works under CC0 do not require attribution. When citing the work, you should
18             # not imply endorsement by the author.
19             #
20              
21              
22             use Moose::Exporter;
23 2     2   449 use Sub::Install 'install_sub';
  2         4  
  2         14  
24 2     2   70 use MooseX::AttributeShortcuts ();
  2         4  
  2         15  
25 2     2   1509  
  2         906267  
  2         353  
26             my ($mods) = @_;
27             sub {
28 8     8   295 @_ = ( shift, shift, @{$mods}, @_ );
29             goto &Moose::has;
30 8     8   336460 };
  8         50  
31 8         44 }
32 8         50  
33             my %mods = (
34             lazy => [ is => "lazy", builder => ],
35             map +( $_ => [ is => $_, required => 1 ] ), qw( ro rwp rw ),
36             );
37             install_sub { into => __PACKAGE__, as => $_, code => _modified_has $mods{$_} }
38             for keys %mods;
39              
40             Moose::Exporter->setup_import_methods #
41             ( with_meta => [ keys %mods ], also => "MooseX::AttributeShortcuts" );
42              
43             1;
44              
45              
46             =pod
47              
48             =head1 NAME
49              
50             MooseX::ShortHas - shortcuts for common Moose has attribute configurations
51              
52             =head1 VERSION
53              
54             version 1.222491
55              
56             =head1 SYNOPSIS
57              
58             Instead of:
59              
60             use Moose;
61            
62             has hro => is => ro => required => 1;
63             has hlazy => is => lazy => builder => sub { 2 };
64             has hrwp => is => rwp => required => 1;
65             has hrw => is => rw => required => 1;
66              
67             You can now write:
68              
69             use Moose;
70             use MooseX::ShortHas;
71            
72             ro "hro";
73             lazy hlazy => sub { 2 };
74             rwp "hrwp";
75             rw "hrw";
76              
77             And options can be added or overriden by appending them:
78              
79             ro hro_opt => required => 0;
80              
81             =head1 DESCRIPTION
82              
83             L<Moose>'s C<has> asks developers to repeat themselves a lot to set up
84             attributes, and since its inceptions the most common configurations of
85             attributes have crystallized through long usage.
86              
87             This module provides sugar shortcuts that wrap around has under the appropriate
88             names to reduce the effort of setting up an attribute to naming it with a
89             shortcut.
90              
91             =head1 EXPORTS
92              
93             =head2 ro, rwp, rw
94              
95             These three work the same, they convert a call like this:
96              
97             ro $name => @extra_args;
98              
99             To this corresponding has call:
100              
101             has $name => is => ro => required => 1 => @extra_args;
102              
103             The appending of extra args makes it easy to override the required if
104             necessary.
105              
106             =head2 lazy
107              
108             This one is slightly different than the others, as lazy arguments don't require
109             a constructor value, but almost always want a builder of some kind:
110              
111             lazy $name => @extra_args;
112              
113             Corresponds to:
114              
115             has $name => is => lazy => builder => @extra_args;
116              
117             The first extra argument is thus expected to be any of the values appropriate
118             for the builder option.
119              
120             =head1 SEE ALSO
121              
122             =over
123              
124             =item *
125              
126             L<Muuse> - automatically wraps this module into Moose
127              
128             =item *
129              
130             L<Muuse::Role> - automatically wraps this module into Moose::Role
131              
132             =item *
133              
134             L<MooX::ShortHas>, L<Mu> - the Moo-related predecessors of this module
135              
136             =item *
137              
138             L<MooseX::MungeHas> - a different module for creating your own has on all of
139             Moo/Moose/Mouse
140              
141             =back
142              
143             =for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan
144              
145             =head1 SUPPORT
146              
147             =head2 Bugs / Feature Requests
148              
149             Please report any bugs or feature requests through the issue tracker
150             at L<https://github.com/wchristian/MooseX-ShortHas/issues>.
151             You will be notified automatically of any progress on your issue.
152              
153             =head2 Source Code
154              
155             This is open source software. The code repository is available for
156             public review and contribution under the terms of the license.
157              
158             L<https://github.com/wchristian/MooseX-ShortHas>
159              
160             git clone https://github.com/wchristian/MooseX-ShortHas.git
161              
162             =head1 AUTHOR
163              
164             Christian Walde <walde.christian@gmail.com>
165              
166             =head1 CONTRIBUTORS
167              
168             =for stopwords Christian Walde Graham Knop Zakariyya Mughal mst - Matt S. Trout (cpan:MSTROUT)
169              
170             =over 4
171              
172             =item *
173              
174             Christian Walde <walde@united-domains.de>
175              
176             =item *
177              
178             Graham Knop <haarg@haarg.org>
179              
180             =item *
181              
182             Zakariyya Mughal <zaki.mughal@gmail.com>
183              
184             =item *
185              
186             mst - Matt S. Trout (cpan:MSTROUT) <mst@shadowcat.co.uk>
187              
188             =back
189              
190             =head1 COPYRIGHT AND LICENSE
191              
192              
193             Christian Walde has dedicated the work to the Commons by waiving all of his
194             or her rights to the work worldwide under copyright law and all related or
195             neighboring legal rights he or she had in the work, to the extent allowable by
196             law.
197              
198             Works under CC0 do not require attribution. When citing the work, you should
199             not imply endorsement by the author.
200              
201             =cut