| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MooseX::SlurpyConstructor; # git description: 1.2-17-g7df5114 |
|
2
|
|
|
|
|
|
|
|
|
3
|
8
|
|
|
8
|
|
4173079
|
use strict; |
|
|
8
|
|
|
|
|
16
|
|
|
|
8
|
|
|
|
|
211
|
|
|
4
|
8
|
|
|
8
|
|
30
|
use warnings; |
|
|
8
|
|
|
|
|
9
|
|
|
|
8
|
|
|
|
|
324
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.30'; |
|
7
|
|
|
|
|
|
|
|
|
8
|
8
|
|
|
8
|
|
427
|
use Moose 0.94 (); |
|
|
8
|
|
|
|
|
346519
|
|
|
|
8
|
|
|
|
|
175
|
|
|
9
|
8
|
|
|
8
|
|
38
|
use Moose::Exporter; |
|
|
8
|
|
|
|
|
8
|
|
|
|
8
|
|
|
|
|
52
|
|
|
10
|
8
|
|
|
8
|
|
254
|
use Moose::Util::MetaRole; |
|
|
8
|
|
|
|
|
11
|
|
|
|
8
|
|
|
|
|
209
|
|
|
11
|
8
|
|
|
8
|
|
3147
|
use MooseX::SlurpyConstructor::Role::Object; |
|
|
8
|
|
|
|
|
48
|
|
|
|
8
|
|
|
|
|
251
|
|
|
12
|
8
|
|
|
8
|
|
3048
|
use MooseX::SlurpyConstructor::Trait::Class; |
|
|
8
|
|
|
|
|
18
|
|
|
|
8
|
|
|
|
|
228
|
|
|
13
|
8
|
|
|
8
|
|
3122
|
use MooseX::SlurpyConstructor::Trait::Attribute; |
|
|
8
|
|
|
|
|
15
|
|
|
|
8
|
|
|
|
|
1249
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
{ |
|
16
|
|
|
|
|
|
|
my %meta_stuff = ( |
|
17
|
|
|
|
|
|
|
base_class_roles => ['MooseX::SlurpyConstructor::Role::Object'], |
|
18
|
|
|
|
|
|
|
class_metaroles => { |
|
19
|
|
|
|
|
|
|
class => ['MooseX::SlurpyConstructor::Trait::Class'], |
|
20
|
|
|
|
|
|
|
attribute => ['MooseX::SlurpyConstructor::Trait::Attribute'], |
|
21
|
|
|
|
|
|
|
}, |
|
22
|
|
|
|
|
|
|
); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
if ( Moose->VERSION < 1.9900 ) { |
|
25
|
|
|
|
|
|
|
require MooseX::SlurpyConstructor::Trait::Method::Constructor; |
|
26
|
|
|
|
|
|
|
push @{$meta_stuff{class_metaroles}{constructor}}, 'MooseX::SlurpyConstructor::Trait::Method::Constructor'; |
|
27
|
|
|
|
|
|
|
} |
|
28
|
|
|
|
|
|
|
else { |
|
29
|
|
|
|
|
|
|
push @{$meta_stuff{class_metaroles}{class}}, |
|
30
|
|
|
|
|
|
|
'MooseX::SlurpyConstructor::Trait::Class'; |
|
31
|
|
|
|
|
|
|
push @{$meta_stuff{role_metaroles}{role}}, |
|
32
|
|
|
|
|
|
|
'MooseX::SlurpyConstructor::Trait::Role'; |
|
33
|
|
|
|
|
|
|
push @{$meta_stuff{role_metaroles}{application_to_class}}, |
|
34
|
|
|
|
|
|
|
'MooseX::SlurpyConstructor::Trait::ApplicationToClass'; |
|
35
|
|
|
|
|
|
|
push @{$meta_stuff{role_metaroles}{application_to_role}}, |
|
36
|
|
|
|
|
|
|
'MooseX::SlurpyConstructor::Trait::ApplicationToRole'; |
|
37
|
|
|
|
|
|
|
push @{$meta_stuff{role_metaroles}{applied_attribute}}, |
|
38
|
|
|
|
|
|
|
'MooseX::SlurpyConstructor::Trait::Attribute'; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Moose::Exporter->setup_import_methods( |
|
42
|
|
|
|
|
|
|
%meta_stuff, |
|
43
|
|
|
|
|
|
|
); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
1; |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# ABSTRACT: Make your object constructor collect all unknown attributes |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
__END__ |
|
51
|
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=pod |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=encoding UTF-8 |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 NAME |
|
57
|
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
MooseX::SlurpyConstructor - Make your object constructor collect all unknown attributes |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=head1 VERSION |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
version 1.30 |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
package My::Class; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
use Moose; |
|
69
|
|
|
|
|
|
|
use MooseX::SlurpyConstructor; |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
has fixed => ( |
|
72
|
|
|
|
|
|
|
is => 'ro', |
|
73
|
|
|
|
|
|
|
); |
|
74
|
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
has slurpy => ( |
|
76
|
|
|
|
|
|
|
is => 'ro', |
|
77
|
|
|
|
|
|
|
slurpy => 1, |
|
78
|
|
|
|
|
|
|
); |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
package main; |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
ASDF->new({ |
|
83
|
|
|
|
|
|
|
fixed => 100, unknown1 => "a", unknown2 => [ 1..3 ] |
|
84
|
|
|
|
|
|
|
})->dump; |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# returns: |
|
87
|
|
|
|
|
|
|
# $VAR1 = bless( { |
|
88
|
|
|
|
|
|
|
# 'slurpy' => { |
|
89
|
|
|
|
|
|
|
# 'unknown2' => [ |
|
90
|
|
|
|
|
|
|
# 1, |
|
91
|
|
|
|
|
|
|
# 2, |
|
92
|
|
|
|
|
|
|
# 3 |
|
93
|
|
|
|
|
|
|
# ], |
|
94
|
|
|
|
|
|
|
# 'unknown1' => 'a' |
|
95
|
|
|
|
|
|
|
# }, |
|
96
|
|
|
|
|
|
|
# 'fixed' => 100 |
|
97
|
|
|
|
|
|
|
# }, 'ASDF' ); |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Including this module within L<Moose>-based classes, and declaring an |
|
102
|
|
|
|
|
|
|
attribute as 'slurpy' will allow capturing of all unknown constructor |
|
103
|
|
|
|
|
|
|
arguments in the given attribute. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
As of L<Moose> 1.9900, this module can also be used in a role, in which case the |
|
106
|
|
|
|
|
|
|
constructor of the consuming class will become slurpy. |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 OPTIONAL RESTRICTIONS |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
No additional options are added to your C<slurpy> attribute, so if you want to |
|
111
|
|
|
|
|
|
|
make it read-only, or restrict its type constraint to a C<HashRef> of specific |
|
112
|
|
|
|
|
|
|
types, you should state that yourself. Typical usage may include any or all of |
|
113
|
|
|
|
|
|
|
the options below: |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
has slurpy => ( |
|
116
|
|
|
|
|
|
|
is => 'ro', |
|
117
|
|
|
|
|
|
|
isa => 'HashRef', |
|
118
|
|
|
|
|
|
|
init_arg => undef, |
|
119
|
|
|
|
|
|
|
lazy => 1, |
|
120
|
|
|
|
|
|
|
default => sub { {} }, |
|
121
|
|
|
|
|
|
|
traits => ['Hash'], |
|
122
|
|
|
|
|
|
|
handles => { |
|
123
|
|
|
|
|
|
|
slurpy_values => 'elements', |
|
124
|
|
|
|
|
|
|
}, |
|
125
|
|
|
|
|
|
|
); |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
For more information on these options, see L<Moose::Manual::Attributes> and |
|
128
|
|
|
|
|
|
|
L<Moose::Meta::Attribute::Native::Trait::Hash>. |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=over 4 |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=item * L<MooseX::StrictConstructor> |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
The opposite of this module, making constructors die on unknown arguments. |
|
137
|
|
|
|
|
|
|
If both of these are used together, L<MooseX::StrictConstructor> will always |
|
138
|
|
|
|
|
|
|
take precedence. |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
This module can also be used in migrating code from vanilla L<Moose> to |
|
141
|
|
|
|
|
|
|
using L<MooseX::StrictConstructor>. That was one of my original motivations |
|
142
|
|
|
|
|
|
|
for writing it; to allow staged migration. |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=back |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head1 HISTORY |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=for stopwords Walde |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
This module was originally written by Mark Morgan C<< <makk384@gmail.com> >>, |
|
151
|
|
|
|
|
|
|
with some bugfix patches by Christian Walde. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
It was rewritten for Moose 2.0 by Karen Etheridge |
|
154
|
|
|
|
|
|
|
C<< <ether@cpan.org> >>, drawing heavily on L<MooseX::StrictConstructor>. |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Thanks to the folks from the Moose mailing list and IRC channels for |
|
159
|
|
|
|
|
|
|
helping me find my way around some of the Moose bits I didn't |
|
160
|
|
|
|
|
|
|
know of before writing this module. |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=head1 SUPPORT |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-SlurpyConstructor> |
|
165
|
|
|
|
|
|
|
(or L<bug-MooseX-SlurpyConstructor@rt.cpan.org|mailto:bug-MooseX-SlurpyConstructor@rt.cpan.org>). |
|
166
|
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
There is also a mailing list available for users of this distribution, at |
|
168
|
|
|
|
|
|
|
L<http://lists.perl.org/list/moose.html>. |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
There is also an irc channel available for users of this distribution, at |
|
171
|
|
|
|
|
|
|
L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>. |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 AUTHORS |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=over 4 |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
=item * |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
Mark Morgan <makk384@gmail.com> |
|
180
|
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
=item * |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=back |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
This software is copyright (c) 2009 by Karen Etheridge. |
|
190
|
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
192
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
193
|
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=cut |