line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::SlurpyConstructor::Role::Object; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
7
|
|
|
7
|
|
170
|
$MooseX::SlurpyConstructor::Role::Object::VERSION = '1.2'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# applied as base_class_roles => [ __PACKAGE__ ], for all Moose versions. |
7
|
7
|
|
|
7
|
|
5438
|
use Moose::Role; |
|
7
|
|
|
|
|
38207
|
|
|
7
|
|
|
|
|
46
|
|
8
|
|
|
|
|
|
|
|
9
|
7
|
|
|
7
|
|
65241
|
use namespace::autoclean; |
|
7
|
|
|
|
|
11030
|
|
|
7
|
|
|
|
|
41
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
after BUILDALL => sub { |
12
|
|
|
|
|
|
|
my $self = shift; |
13
|
|
|
|
|
|
|
my $params = shift; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
my %attrs = ( |
16
|
|
|
|
|
|
|
__INSTANCE__ => 1, |
17
|
|
|
|
|
|
|
map { $_ => 1 } |
18
|
|
|
|
|
|
|
grep { defined } |
19
|
|
|
|
|
|
|
map { $_->init_arg } $self->meta->get_all_attributes |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my @extra = sort grep { !$attrs{$_} } keys %{$params}; |
23
|
|
|
|
|
|
|
return if not @extra; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# XXX TODO: stuff all these into the slurpy attr. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# find the slurpy attr |
28
|
|
|
|
|
|
|
# TODO: use the metaclass slurpy_attr to find this: |
29
|
|
|
|
|
|
|
# if $self->meta->slurpy_attr |
30
|
|
|
|
|
|
|
# and then the check for multiple slurpy attrs can be done at |
31
|
|
|
|
|
|
|
# composition time. |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
my $slurpy_attr = $self->meta->slurpy_attr; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Moose->throw_error('Found extra construction arguments, but there is no \'slurpy\' attribute present!') if not $slurpy_attr; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my %slurpy_values; |
38
|
|
|
|
|
|
|
@slurpy_values{@extra} = @{$params}{@extra}; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
$slurpy_attr->set_value( $self, \%slurpy_values ); |
41
|
|
|
|
|
|
|
}; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
1; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# ABSTRACT: A role which implements a slurpy constructor for Moose::Object |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=pod |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 NAME |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
MooseX::SlurpyConstructor::Role::Object - A role which implements a slurpy constructor for Moose::Object |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 VERSION |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
version 1.2 |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=head1 SYNOPSIS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Moose::Util::MetaRole::apply_base_class_roles( |
62
|
|
|
|
|
|
|
for_class => $caller, |
63
|
|
|
|
|
|
|
roles => |
64
|
|
|
|
|
|
|
['MooseX::SlurpyConstructor::Role::Object'], |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 DESCRIPTION |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
When you use C<MooseX::SlurpyConstructor>, your objects will have this |
70
|
|
|
|
|
|
|
role applied to them. It provides a method modifier for C<BUILDALL()> |
71
|
|
|
|
|
|
|
from C<Moose::Object> that saves all unrecognized attributes. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head1 AUTHORS |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=over 4 |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=item * |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
Mark Morgan <makk384@gmail.com> |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=item * |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=back |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
This software is copyright (c) 2011 by Karen Etheridge. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
92
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
__END__ |
98
|
|
|
|
|
|
|
|