line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package MooseX::SlurpyConstructor::Trait::Attribute; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
7
|
|
|
7
|
|
163
|
$MooseX::SlurpyConstructor::Trait::Attribute::VERSION = '1.2'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# applied as class_metaroles => { attribute => [ __PACKAGE__ ] }. |
7
|
|
|
|
|
|
|
|
8
|
7
|
|
|
7
|
|
40
|
use Moose::Role; |
|
7
|
|
|
|
|
14
|
|
|
7
|
|
|
|
|
88
|
|
9
|
|
|
|
|
|
|
|
10
|
7
|
|
|
7
|
|
52709
|
use namespace::autoclean; |
|
7
|
|
|
|
|
16
|
|
|
7
|
|
|
|
|
67
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has slurpy => ( |
13
|
|
|
|
|
|
|
is => 'ro', |
14
|
|
|
|
|
|
|
isa => 'Bool', |
15
|
|
|
|
|
|
|
default => 0, |
16
|
|
|
|
|
|
|
); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
before attach_to_class => sub { |
19
|
|
|
|
|
|
|
my ($self, $meta) = @_; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
return if not $self->slurpy; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# TODO: test these cases |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
# save the slurpy attribute in the metaclass, for quick access at |
26
|
|
|
|
|
|
|
# object construction time. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Moose->throw_error('Attempting to use slurpy attribute \'', $self->name, |
29
|
|
|
|
|
|
|
'\' in class ', $meta->name, |
30
|
|
|
|
|
|
|
' that does not do the MooseX::SlurpyConstructor::Trait::Class role!') |
31
|
|
|
|
|
|
|
# if not $meta->does_role('MooseX::SlurpyConstructor::Trait::Class'); |
32
|
|
|
|
|
|
|
if not $meta->meta->find_attribute_by_name('slurpy_attr'); |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Moose->throw_error('Attempting to use slurpy attribute ', $self->name, |
35
|
|
|
|
|
|
|
' in class ', $meta->name, |
36
|
|
|
|
|
|
|
' that already has a slurpy attribute (', $meta->slurpy_attr->name, ')!') |
37
|
|
|
|
|
|
|
if $meta->slurpy_attr; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
$meta->slurpy_attr($self); |
40
|
|
|
|
|
|
|
}; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
1; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# ABSTRACT: A role to store the slurpy attribute in the metaclass |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=pod |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head1 NAME |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
MooseX::SlurpyConstructor::Trait::Attribute - A role to store the slurpy attribute in the metaclass |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 VERSION |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
version 1.2 |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head1 DESCRIPTION |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Adds the 'slurpy' attribute to attributes used in |
61
|
|
|
|
|
|
|
MooseX::SlurpyConstructor-aware classes, and checks that only one such |
62
|
|
|
|
|
|
|
attribute is present at any time. |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 AUTHORS |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=over 4 |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item * |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Mark Morgan <makk384@gmail.com> |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item * |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Karen Etheridge <ether@cpan.org> |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=back |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This software is copyright (c) 2011 by Karen Etheridge. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
83
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=cut |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
__END__ |
89
|
|
|
|
|
|
|
|