| 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
Condition33%1/3
defined $class and $class =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/
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*)*$/
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 31 | 395 | ▶ | return 1 if substr( $symbol, -2, 2 ) ne '::'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $class and $class =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/
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*)*$/
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
defined $mixin and $mixin =~ /^[a-zA-Z_]\w*(?:::[a-zA-Z_]\w*)*$/
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*)*$/
| |||||||||||||||||||||||||||||
| 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
Condition100%3/3
class_exists($mixin) or GX::Meta::Util::load_module($mixin)
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)
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 4 | return; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 218 | 1; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | __END__ | ||||||||||||||||||||||||||||