GX/Meta/Method.pm

filter: Statementstmt 89.5% 43 / 48 Branchbran 66.6% 8 / 12 Conditioncond 58.3% 7 / 12 MC/DCmcdc 14.2% 1 / 7 Subroutinesub 93.7% 15 / 16 Podpod 100% 6 / 6 totaltotal 79.2% 80 / 101 CC 12 SCAR 13.1
CC
12
Cov
81%
new
8.8
code_attributes
4.2
_overload_code_dereference
2.1
CRAP 3.7
« GX/HTTP/Status.pm ↑ Summary GX/Meta/Attribute/Object.pm »
1 # ----------------------------------------------------------------------------------------------------------------------
2 # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de>
3 # File: GX/Meta/Method.pm
4 # ----------------------------------------------------------------------------------------------------------------------
5  
6 package GX::Meta::Method;
7  
8 270 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 270 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 270 ▶use GX::Meta::Constants qw( REGEX_METHOD_NAME );
Subroutine BEGIN: called CC=1 SCAR=0.0
12 270 ▶use GX::Meta::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 270 ▶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 10670 ▶ 'bool' => sub { 1 },
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
23 0 ▶ '0+' => sub { $_[0] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
24 136 ▶ '""' => sub { $_[0]->name },
Subroutine __ANON__: called CC=1 SCAR=0.0
25 270 '&{}' => \&_overload_code_dereference,
26 270 'fallback' => 1;
27  
28  
29 # ----------------------------------------------------------------------------------------------------------------------
30 # Constructor
31 # ----------------------------------------------------------------------------------------------------------------------
32  
33 26297 ▶sub new {
Subroutine new: called CC=7 SCAR=21.8
Pod documented
34  
35 26297 my $class = shift;
36 26297 my %args = @_;
37  
38 26297 ▶ if ( ! defined $args{'class'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"class"}) 0 26297 26297
39 0 complain "Missing argument (\"class\")";
40 }
41  
42 26297 ▶ if ( ! blessed( $args{'class'} ) || ! $args{'class'}->isa( 'GX::Meta::Class' ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (builtin::blessed($args{"class"}) and $args{"class"}->isa("GX::Meta::Class")) 0 26297 26297
Condition33%1/3
builtin::blessed($args{"class"}) and $args{"class"}->isa("GX::Meta::Class")
!ll&&!rl&&r
0026297
MC/DC0%0/2
builtin::blessed($args{"class"}) and $args{"class"}->isa("GX::Meta::Class")
builtin::blessed($args{"class"}) $args{"class"}->isa("GX::Meta::Class")
Truth table33%1/3
A and B
A= builtin::blessed($args{"class"})B= $args{"class"}->isa("GX::Meta::Class")
ABresult
0X0
100
111
43 0 complain "Invalid argument (\"class\" must be a GX::Meta::Class object)";
44 }
45  
46 26297 ▶ if ( ! defined $args{'name'} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $args{"name"}) 0 26297 26297
47 0 complain "Missing argument (\"name\")";
48 }
49  
50 26297 ▶ if ( $args{'name'} !~ REGEX_METHOD_NAME ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($args{"name"} =~ /^[a-zA-Z_]\w*$/) 0 26297 26297
51 0 complain "Invalid argument (\"$args{'name'}\" is not a valid method name)";
52 }
53  
54 26297 my $method_full_name = $args{'class'}->name . '::' . $args{'name'};
55  
56 26297 ▶ if ( ! defined &{$method_full_name} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined &{$method_full_name;}) 1 26296 26297
57 1 complain "Method &$method_full_name does not exist";
58 }
59  
60 my $self = bless {
61 'class' => $args{'class'},
62 'full_name' => $method_full_name,
63 26296 'name' => $args{'name'}
64 }, $class;
65  
66 26296 weaken $self->{'class'};
67  
68 26296 return $self;
69  
70 }
71  
72  
73 # ----------------------------------------------------------------------------------------------------------------------
74 # Public methods
75 # ----------------------------------------------------------------------------------------------------------------------
76  
77 701 ▶sub class {
Subroutine class: called CC=1 SCAR=0.0
Pod documented
78  
79 701 return $_[0]->{'class'};
80  
81 }
82  
83 692 ▶sub code {
Subroutine code: called CC=2 SCAR=6.9
Pod documented
84  
85 692 ▶ return defined &{$_[0]->{'full_name'}} ? \&{$_[0]->{'full_name'}} : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined &{$_[0]{'full_name'};} ? : 691 1 692
86  
87 }
88  
89 672 ▶sub code_attributes {
Subroutine code_attributes: called CC=4 SCAR=14.5
Pod documented
90  
91 672 ▶ return @{ ( $_[0]->class || return )->code_attribute_store->{ $_[0]->code || return } || return };
Condition66%4/6
($_[0]->class || (return))->code_attribute_store->{$_[0]->code or return} || (return)
l!l
24648
$_[0]->class || (return)
l!l
6720
$_[0]->code || (return)
l!l
6720
MC/DC100%1/1
($_[0]->class || (return))->code_attribute_store->{$_[0]->code or return} || (return)
($_[0]->class || (return))->code_attribute_store->{$_[0]->code or return}
MC/DC0%0/1
$_[0]->class || (return)
$_[0]->class
MC/DC0%0/1
$_[0]->code || (return)
$_[0]->code
Truth table100%2/2
A
A= ($_[0]->class || (return))->code_attribute_store->{$_[0]->code or return}
Aresult
11
00
Truth table50%1/2
A
A= $_[0]->class
Aresult
11
00
Truth table50%1/2
A
A= $_[0]->code
Aresult
11
00
92  
93 }
94  
95 2 ▶sub full_name {
Subroutine full_name: called CC=1 SCAR=0.0
Pod documented
96  
97 2 return $_[0]->{'full_name'};
98  
99 }
100  
101 382 ▶sub name {
Subroutine name: called CC=1 SCAR=0.0
Pod documented
102  
103 382 return $_[0]->{'name'};
104  
105 }
106  
107  
108 # ----------------------------------------------------------------------------------------------------------------------
109 # Private methods
110 # ----------------------------------------------------------------------------------------------------------------------
111  
112 4 ▶sub _overload_code_dereference {
Subroutine _overload_code_dereference: called CC=2 SCAR=7.2
113  
114 4 ▶ return $_[0]->code || complain( "Undefined subroutine &" . $_[0]->full_name . " called" );
Condition66%2/3
$_[0]->code || &complain('Undefined subroutine &' . $_[0]->full_name . ' called')
l!l&&r!l&&!r
301
MC/DC0%0/2
$_[0]->code || &complain('Undefined subroutine &' . $_[0]->full_name . ' called')
$_[0]->code &complain('Undefined subroutine &' . $_[0]->full_name . ' called')
Truth table33%1/3
A || B
A= $_[0]->codeB= &complain('Undefined subroutine &' . $_[0]->full_name . ' called')
ABresult
1X1
011
000
115  
116 }
117  
118  
119 270 1;
120  
121 __END__
« GX/HTTP/Status.pm ↑ Summary GX/Meta/Attribute/Object.pm »