Privacy/Meta/Class/Role.pm

filter: Statementstmt 100% 54 / 54 Branchbran 62.5% 5 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 12 / 12 Podpod n/a totaltotal 95.9% 71 / 74 CC 7 SCAR 6.7
CC
7
Cov
95%
__ANON__
3.0
add_private_method
3.0
add_protected_method
3.0
CRAP 2.0
« Privacy/Meta/Attribute/Protected.pm ↑ Summary Privacy/Meta/Method/Protected.pm »
1 package MooseX::Privacy::Meta::Class::Role;
2 8 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
3 8 $MooseX::Privacy::Meta::Class::Role::VERSION = '0.05';
4 }
5  
6 # ABSTRACT: Private and Protected parameterized roles
7  
8 8 ▶use MooseX::Role::Parameterized;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 8 ▶use Scalar::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 8 ▶use Carp qw/confess/;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 8 ▶use MooseX::Types::Moose qw/Str ArrayRef/;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 8 ▶use MooseX::Privacy::Meta::Method::Protected;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 8 ▶use MooseX::Privacy::Meta::Method::Private;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 parameter name => ( isa => 'Str', required => 1, );
17  
18 16 ▶role {
Subroutine __ANON__: called CC=1 SCAR=0.0
19 16 my $p = shift;
20  
21 16 my $name = $p->name;
22 16 my $local_methods = "local_" . $name . "_methods";
23 16 my $local_attributes = "local_" . $name . "_attributes";
24 16 my $push_method = "_push_" . $name . "_method";
25 16 my $push_attribute = "_push_" . $name . "_attribute";
26 16 my $count_methods = "_count_" . $name . "_methods";
27 16 my $count_attributes = "_count_" . $name . "_attributes";
28 16 my $get_method = 'get_' . $name . '_method';
29 16 my $get_all_mehods = 'get_all_' . $name . '_methods';
30 16 my $get_all_methods_name = 'get_all_' . $name . '_method_names';
31 16 my $meta_method = "add_" . $name . "_method";
32  
33 has $local_methods => (
34 traits => ['Array'],
35 is => 'ro',
36 isa => ArrayRef [Str],
37 required => 1,
38 24 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
39 16 auto_deref => 1,
40 handles => { $push_method => 'push', $count_methods => 'count' },
41 );
42  
43 has $local_attributes => (
44 traits => ['Array'],
45 is => 'ro',
46 isa => ArrayRef [Str],
47 required => 1,
48 24 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
49 16 auto_deref => 1,
50 handles =>
51 { $push_attribute => 'push', $count_attributes => 'count' },
52 );
53  
54 1 ▶ method $meta_method => sub {
Subroutine add_protected_method: called CC=3 SCAR=11.1
Subroutine add_private_method: called CC=3 SCAR=11.1
55 1 my ( $self, $method_name, $body ) = @_;
56  
57 1 my $class = "MooseX::Privacy::Meta::Method::" . ( ucfirst $name );
58  
59 1 ▶ my $method = blessed $body ? $body : $class->wrap(
Branch: 2 branches
BranchTrueFalseTotal
builtin::blessed($body) ? : 0 1 1
builtin::blessed($body) ? : 2 4 6
60 name => $method_name,
61 package_name => $self->name,
62 body => $body
63 );
64  
65 1 ▶ confess $method_name . " is not a " . $name . " method"
Branch: 2 branches
BranchTrueFalseTotal
unless $method->isa($class) 0 1 1
unless $method->isa($class) 0 6 6
66 unless $method->isa($class);
67  
68 1 $self->add_method( $method->name, $method );
69 1 $self->$push_method( $method->name );
70 16 };
71 2 };
72  
73 2 1;
74  
75  
76 __END__
« Privacy/Meta/Attribute/Protected.pm ↑ Summary Privacy/Meta/Method/Protected.pm »