File: | lib/Code/Statistics/SlurpyConstructor/Role/Attribute.pm |
Coverage: | 100.0% |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | ## no critic | ||||||
2 | package Code::Statistics::SlurpyConstructor::Role::Attribute; | ||||||
3 | |||||||
4 | # ABSTRACT: Internal class for Code::Statistics::SlurpyConstructor | ||||||
5 | |||||||
6 | 1 1 1 | 0 0 0 | use Moose::Role; | ||||
7 | |||||||
8 | has slurpy => ( | ||||||
9 | is => 'ro', | ||||||
10 | isa => 'Bool', | ||||||
11 | default => 0, | ||||||
12 | ); | ||||||
13 | |||||||
14 | before attach_to_class => sub { | ||||||
15 | my ( $self, $meta ) = @_; | ||||||
16 | |||||||
17 | return if not $self->slurpy; | ||||||
18 | |||||||
19 | my @slurpy = | ||||||
20 | map { $_->name } | ||||||
21 | grep { $_->slurpy } | ||||||
22 | $meta->get_all_attributes; | ||||||
23 | |||||||
24 | if ( scalar @slurpy ) { | ||||||
25 | my $message = sprintf( | ||||||
26 | "Can't add mutliple slurpy attributes to a class, attempting to add '%s', existing slurpy attribute '%s'", | ||||||
27 | $self->name, | ||||||
28 | $slurpy[ 0 ], | ||||||
29 | ); | ||||||
30 | die $message; | ||||||
31 | } | ||||||
32 | }; | ||||||
33 | |||||||
34 | 1 1 1 | 0 0 0 | no Moose::Role; | ||||
35 | |||||||
36 | 1; | ||||||
37 |