File Coverage

blib/lib/MooseX/SlurpyConstructor/Role/Object.pm
Criterion Covered Total %
statement 6 6 100.0
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 8 8 100.0


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