GX/Class/Util.pm

filter: Statementstmt 93.3% 42 / 45 Branchbran 78.5% 11 / 14 Conditioncond 50.0% 6 / 12 MC/DCmcdc 25.0% 2 / 8 Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 80.0% 72 / 90 CC 14 SCAR 18.8
CC
14
Cov
83%
mixin
11.1
class_exists
5.2
BEGIN
1.0
CRAP 6.6
« GX/Dispatcher.pm ↑ Summary GX/HTTP/Message.pm »
1 # ----------------------------------------------------------------------------------------------------------------------
2 # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de>
3 # File: GX/Class/Util.pm
4 # ----------------------------------------------------------------------------------------------------------------------
5  
6 package GX::Class::Util;
7  
8 218 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 218 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 218 ▶use GX::Exception;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 218 ▶use GX::Meta::Constants qw( REGEX_CLASS_NAME );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 218 ▶use GX::Meta::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15  
16 # ----------------------------------------------------------------------------------------------------------------------
17 # Public functions
18 # ----------------------------------------------------------------------------------------------------------------------
19  
20 534 ▶sub class_exists {
Subroutine class_exists: called CC=5 SCAR=16.6
Pod documented
21  
22 534 my $class = shift;
23  
24 534 ▶ if ( ! defined $class || $class !~ REGEX_CLASS_NAME ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $class and $class =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/) 0 534 534
Condition33%1/3
defined $class and $class =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/
!ll&&!rl&&r
00534
MC/DC0%0/2
defined $class and $class =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/
defined $class $class =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/
Truth table33%1/3
A and B
A= defined $classB= $class =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/
ABresult
0X0
100
111
25 0 complain "Undefined or invalid class name";
26 }
27  
28 218 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 534 ▶ while ( my $symbol = each %{"${class}::"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $symbol = each %{"${class}::";})) 395 407 802
31 395 ▶ return 1 if substr( $symbol, -2, 2 ) ne '::';
Branch: 1 branch
BranchTrueFalseTotal
if substr($symbol, -2, 2) ne "::" 127 268 395
32 }
33  
34 407 return 0;
35  
36 }
37  
38 5 ▶sub mixin {
Subroutine mixin: called CC=10 SCAR=24.1
Pod documented
39  
40 5 my $class = shift;
41 5 my @mixins = @_;
42  
43 5 ▶ if ( ! defined $class || $class !~ REGEX_CLASS_NAME ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $class and $class =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/) 0 5 5
Condition33%1/3
defined $class and $class =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/
!ll&&!rl&&r
005
MC/DC0%0/2
defined $class and $class =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/
defined $class $class =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/
Truth table33%1/3
A and B
A= defined $classB= $class =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/
ABresult
0X0
100
111
44 0 complain "Undefined or invalid class name";
45 }
46  
47 5 for my $mixin ( @mixins ) {
48  
49 7 ▶ if ( ! defined $mixin || $mixin !~ REGEX_CLASS_NAME ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $mixin and $mixin =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/) 0 7 7
Condition33%1/3
defined $mixin and $mixin =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/
!ll&&!rl&&r
007
MC/DC0%0/2
defined $mixin and $mixin =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/
defined $mixin $mixin =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/
Truth table33%1/3
A and B
A= defined $mixinB= $mixin =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/
ABresult
0X0
100
111
50 0 complain "Undefined or invalid mixin name";
51 }
52  
53 7 ▶ if ( ! class_exists( $mixin ) && ! GX::Meta::Util::load_module( $mixin ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (class_exists($mixin) or GX::Meta::Util::load_module($mixin)) 1 6 7
Condition100%3/3
class_exists($mixin) or GX::Meta::Util::load_module($mixin)
l!l&&r!l&&!r
511
MC/DC100%2/2
class_exists($mixin) or GX::Meta::Util::load_module($mixin)
class_exists($mixin) GX::Meta::Util::load_module($mixin)
Truth table100%3/3
A or B
A= class_exists($mixin)B= GX::Meta::Util::load_module($mixin)
ABresult
1X1
011
000
54 1 complain "Mixin package \"$mixin\" is empty";
55 }
56  
57 218 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
58  
59 6 for my $symbol ( keys %{"${mixin}::"} ) {
60 16 local *glob = *{"${mixin}::${symbol}"};
61 16 ▶ *{"${class}::${symbol}"} = *glob{'CODE'} if *glob{'CODE'};
Branch: 1 branch
BranchTrueFalseTotal
if *glob{"CODE"} 12 4 16
62 }
63  
64 }
65  
66 4 return;
67  
68 }
69  
70  
71 218 1;
72  
73 __END__
« GX/Dispatcher.pm ↑ Summary GX/HTTP/Message.pm »