File Coverage

blib/lib/MooseX/SlurpyConstructor/Trait/Attribute.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::Trait::Attribute;
2              
3             our $VERSION = '1.30';
4              
5             # applied as class_metaroles => { attribute => [ __PACKAGE__ ] }.
6              
7 8     8   32 use Moose::Role;
  8         9  
  8         1730  
8              
9 8     8   26681 use namespace::autoclean;
  8         10  
  8         47  
10              
11             has slurpy => (
12             is => 'ro',
13             isa => 'Bool',
14             default => 0,
15             );
16              
17             before attach_to_class => sub {
18             my ($self, $meta) = @_;
19              
20             return if not $self->slurpy;
21              
22             # TODO: test these cases
23              
24             # save the slurpy attribute in the metaclass, for quick access at
25             # object construction time.
26              
27             Moose->throw_error('Attempting to use slurpy attribute \'', $self->name,
28             '\' in class ', $meta->name,
29             ' that does not do the MooseX::SlurpyConstructor::Trait::Class role!')
30             # if not $meta->does_role('MooseX::SlurpyConstructor::Trait::Class');
31             if not $meta->meta->find_attribute_by_name('slurpy_attr');
32              
33             Moose->throw_error('Attempting to use slurpy attribute ', $self->name,
34             ' in class ', $meta->name,
35             ' that already has a slurpy attribute (', $meta->slurpy_attr->name, ')!')
36             if $meta->slurpy_attr;
37              
38             $meta->slurpy_attr($self);
39             };
40              
41             1;
42              
43             # ABSTRACT: A role to store the slurpy attribute in the metaclass
44              
45             __END__
46              
47             =pod
48              
49             =encoding UTF-8
50              
51             =head1 NAME
52              
53             MooseX::SlurpyConstructor::Trait::Attribute - A role to store the slurpy attribute in the metaclass
54              
55             =head1 VERSION
56              
57             version 1.30
58              
59             =head1 DESCRIPTION
60              
61             Adds the C<slurpy> attribute to attributes used in
62             L<MooseX::SlurpyConstructor>-aware classes, and checks that only one such
63             attribute is present at any time.
64              
65             =head1 SUPPORT
66              
67             Bugs may be submitted through L<the RT bug tracker|https://rt.cpan.org/Public/Dist/Display.html?Name=MooseX-SlurpyConstructor>
68             (or L<bug-MooseX-SlurpyConstructor@rt.cpan.org|mailto:bug-MooseX-SlurpyConstructor@rt.cpan.org>).
69              
70             There is also a mailing list available for users of this distribution, at
71             L<http://lists.perl.org/list/moose.html>.
72              
73             There is also an irc channel available for users of this distribution, at
74             L<C<#moose> on C<irc.perl.org>|irc://irc.perl.org/#moose>.
75              
76             =head1 AUTHORS
77              
78             =over 4
79              
80             =item *
81              
82             Mark Morgan <makk384@gmail.com>
83              
84             =item *
85              
86             Karen Etheridge <ether@cpan.org>
87              
88             =back
89              
90             =head1 COPYRIGHT AND LICENSE
91              
92             This software is copyright (c) 2009 by Karen Etheridge.
93              
94             This is free software; you can redistribute it and/or modify it under
95             the same terms as the Perl 5 programming language system itself.
96              
97             =cut