| 1 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 2 | # GX Framework (c) 2009-2011 Jörg A. Uzarek <uzarek@runlevelnull.de> | ||||||||||||||||||||||||||||
| 3 | # File: GX/Meta/Delegator.pm | ||||||||||||||||||||||||||||
| 4 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | package GX::Meta::Delegator; | ||||||||||||||||||||||||||||
| 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 | 32 | ▶ | 'bool' => sub { 1 }, | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 23 | 0 | ▶ | '0+' => sub { $_[0] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 24 | 16 | ▶ | '""' => sub { $_[0]->name }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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 | 16 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=7 SCAR=22.6
Pod
documented
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 16 | my $class = shift; | |||||||||||||||||||||||||||
| 36 | 16 | my %args = @_; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 16 | for ( qw( attribute code name ) ) { | |||||||||||||||||||||||||||
| 39 | 48 | ▶ | defined $args{$_} or complain "Missing argument (\"$_\")"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 16 | ▶ | if ( ! ( blessed $args{'attribute'} && $args{'attribute'}->isa( 'GX::Meta::Attribute' ) ) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($args{"attribute"}) and $args{"attribute"}->isa("GX::Meta::Attribute")
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")
| |||||||||||||||||||||||||||||
| 43 | 0 | complain "Invalid argument (\"attribute\" must be a GX::Meta::Attribute object)"; | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 16 | ▶ | if ( ref $args{'code'} ne 'CODE' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | complain "Invalid argument (\"code\" must be a code reference)"; | |||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 16 | ▶ | if ( $args{'name'} !~ REGEX_METHOD_NAME ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 16 | 'name' => $args{'name'} | |||||||||||||||||||||||||||
| 58 | }, $class; | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 16 | weaken $self->{'attribute'}; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 16 | return $self; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 68 | # Public methods | ||||||||||||||||||||||||||||
| 69 | # ---------------------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 16 | ▶ | sub attribute { | ||||||||||||||||||||||||||
|
Subroutine
attribute: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 16 | return $_[0]->{'attribute'}; | |||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 28 | ▶ | sub code { | ||||||||||||||||||||||||||
|
Subroutine
code: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 28 | return $_[0]->{'code'}; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 64 | ▶ | sub name { | ||||||||||||||||||||||||||
|
Subroutine
name: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 64 | return $_[0]->{'name'}; | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 278 | 1; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | __END__ | ||||||||||||||||||||||||||||