| 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
| |||||||||||||||||||||||||||||||||
| 39 | 0 | complain "Missing argument (\"class\")"; | |||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||
| 42 | 26297 | ▶ | if ( ! blessed( $args{'class'} ) || ! $args{'class'}->isa( 'GX::Meta::Class' ) ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
builtin::blessed($args{"class"}) and $args{"class"}->isa("GX::Meta::Class")
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")
| |||||||||||||||||||||||||||||||||
| 43 | 0 | complain "Invalid argument (\"class\" must be a GX::Meta::Class object)"; | |||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||
| 46 | 26297 | ▶ | if ( ! defined $args{'name'} ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 47 | 0 | complain "Missing argument (\"name\")"; | |||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||
| 50 | 26297 | ▶ | if ( $args{'name'} !~ REGEX_METHOD_NAME ) { | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||
| 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)
$_[0]->class || (return)
$_[0]->code || (return)
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}
Truth table50%1/2
A
A= $_[0]->class
Truth table50%1/2
A
A= $_[0]->code
| |||||||||||||||||||||||||||||||||
| 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')
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')
| |||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||
| 119 | 270 | 1; | |||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||
| 121 | __END__ | ||||||||||||||||||||||||||||||||