GX/Meta/Accessor.pm

filter: Statementstmt 85.0% 34 / 40 Branchbran 50.0% 4 / 8 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 80.0% 12 / 15 Podpod 100% 5 / 5 totaltotal 76.7% 56 / 73 CC 7 SCAR 13.9
CC
7
Cov
76%
new
9.6
__ANON__
2.0
__ANON__
2.0
CRAP 4.0
« GX/Meta/Delegator.pm ↑ Summary GX/HTTP/Upload.pm »
1 # ----------------------------------------------------------------------------------------------------------------------
2 # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de>
3 # File: GX/Meta/Accessor.pm
4 # ----------------------------------------------------------------------------------------------------------------------
5  
6 package GX::Meta::Accessor;
7  
8 278 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 278 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 278 ▶use GX::Meta::Constants qw( REGEX_METHOD_NAME );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 278 ▶use GX::Meta::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 278 ▶use Scalar::Util qw( blessed weaken );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16  
17 # ----------------------------------------------------------------------------------------------------------------------
18 # Overloading
19 # ----------------------------------------------------------------------------------------------------------------------
20  
21 use overload
22 9088 ▶ 'bool' => sub { 1 },
Subroutine BEGIN: called CC=1 SCAR=0.8
Subroutine __ANON__: called CC=1 SCAR=0.0
23 0 ▶ '0+' => sub { $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 0 ▶ '""' => sub { $_[0]->name },
Subroutine __ANON__: not called CC=1 SCAR=6.9
25 0 ▶ '&{}' => sub { $_[0]->code },
Subroutine __ANON__: not called CC=1 SCAR=6.9
26 278 'fallback' => 1;
27  
28  
29 # ----------------------------------------------------------------------------------------------------------------------
30 # Constructor
31 # ----------------------------------------------------------------------------------------------------------------------
32  
33 4544 ▶sub new {
Subroutine new: called CC=7 SCAR=22.6
Pod documented
34  
35 4544 my $class = shift;
36 4544 my %args = @_;
37  
38 4544 for ( qw( attribute code name ) ) {
39 13632 ▶ defined $args{$_} or complain "Missing argument (\"$_\")";
Branch: 1 branch
BranchTrueFalseTotal
defined $args{$_} or &complain(qq[Missing argument ("$_")]) 13632 0 13632
40 }
41  
42 4544 ▶ if ( ! ( blessed $args{'attribute'} && $args{'attribute'}->isa( 'GX::Meta::Attribute' ) ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($args{"attribute"}) and $args{"attribute"}->isa("GX::Meta::Attribute")) 0 4544 4544
Condition33%1/3
builtin::blessed($args{"attribute"}) and $args{"attribute"}->isa("GX::Meta::Attribute")
!ll&&!rl&&r
004544
MC/DC0%0/2
builtin::blessed($args{"attribute"}) and $args{"attribute"}->isa("GX::Meta::Attribute")
builtin::blessed($args{"attribute"}) $args{"attribute"}->isa("GX::Meta::Attribute")
Truth table33%1/3
A and B
A= builtin::blessed($args{"attribute"})B= $args{"attribute"}->isa("GX::Meta::Attribute")
ABresult
0X0
100
111
43 0 complain "Invalid argument (\"attribute\" must be a GX::Meta::Attribute object)";
44 }
45  
46 4544 ▶ if ( ref $args{'code'} ne 'CODE' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $args{"code"} ne "CODE") 0 4544 4544
47 0 complain "Invalid argument (\"code\" must be a code reference)";
48 }
49  
50 4544 ▶ if ( $args{'name'} !~ REGEX_METHOD_NAME ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"name"} =~ /^[a-zA-Z_]\w*$/) 0 4544 4544
51 0 complain "Invalid argument (\"name\" must be a method name)";
52 }
53  
54 my $self = bless {
55 'attribute' => $args{'attribute'},
56 'code' => $args{'code'},
57 'name' => $args{'name'},
58 4544 'type' => $args{'type'}
59 }, $class;
60  
61 4544 weaken $self->{'attribute'};
62  
63 4544 return $self;
64  
65 }
66  
67  
68 # ----------------------------------------------------------------------------------------------------------------------
69 # Public methods
70 # ----------------------------------------------------------------------------------------------------------------------
71  
72 28 ▶sub attribute {
Subroutine attribute: called CC=1 SCAR=0.0
Pod documented
73  
74 28 return $_[0]->{'attribute'};
75  
76 }
77  
78 4572 ▶sub code {
Subroutine code: called CC=1 SCAR=0.0
Pod documented
79  
80 4572 return $_[0]->{'code'};
81  
82 }
83  
84 9116 ▶sub name {
Subroutine name: called CC=1 SCAR=0.0
Pod documented
85  
86 9116 return $_[0]->{'name'};
87  
88 }
89  
90 28 ▶sub type {
Subroutine type: called CC=1 SCAR=0.0
Pod documented
91  
92 28 return $_[0]->{'type'};
93  
94 }
95  
96  
97 278 1;
98  
99 __END__
« GX/Meta/Delegator.pm ↑ Summary GX/HTTP/Upload.pm »