| 1 | package Class::Variable; | ||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use 5.008; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; use warnings FATAL => 'all'; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Scalar::Util 'weaken'; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | our $VERSION = '1.002'; # <== update version in pod | |||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | our @EXPORT; | |||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||
| 12 | 1 | my $NS = {}; | |||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | push @EXPORT, 'public'; | |||||||||||||||||||||||||||||||||||||||
| 15 | sub public($;) | ||||||||||||||||||||||||||||||||||||||||
| 16 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
public: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 17 | 2 | my @names = @_; | |||||||||||||||||||||||||||||||||||||||
| 18 | 2 | my $package = (caller)[0]; | |||||||||||||||||||||||||||||||||||||||
| 19 | 2 | foreach my $name (@names) | |||||||||||||||||||||||||||||||||||||||
| 20 | { | ||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 22 | 2 | *{$package.'::'.$name } = get_public_variable($package, $name); | |||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | push @EXPORT, 'protected'; | |||||||||||||||||||||||||||||||||||||||
| 27 | sub protected($;) | ||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
protected: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | my @names = @_; | |||||||||||||||||||||||||||||||||||||||
| 30 | 2 | my $package = (caller)[0]; | |||||||||||||||||||||||||||||||||||||||
| 31 | 2 | foreach my $name (@names) | |||||||||||||||||||||||||||||||||||||||
| 32 | { | ||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 34 | 2 | *{$package.'::'.$name } = get_protected_variable($package, $name); | |||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | push @EXPORT, 'private'; | |||||||||||||||||||||||||||||||||||||||
| 39 | sub private($;) | ||||||||||||||||||||||||||||||||||||||||
| 40 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
private: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 41 | 2 | my @names = @_; | |||||||||||||||||||||||||||||||||||||||
| 42 | 2 | my $package = (caller)[0]; | |||||||||||||||||||||||||||||||||||||||
| 43 | 2 | foreach my $name (@names) | |||||||||||||||||||||||||||||||||||||||
| 44 | { | ||||||||||||||||||||||||||||||||||||||||
| 45 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | *{$package.'::'.$name } = get_private_variable($package, $name); | |||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||
| 50 | sub get_public_variable($$) | ||||||||||||||||||||||||||||||||||||||||
| 51 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_public_variable: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 52 | 2 | my( $package, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||
| 54 | 6 | ▶ | return sub: lvalue | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||
| 55 | { | ||||||||||||||||||||||||||||||||||||||||
| 56 | 6 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 57 | 6 | ▶ | if( | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $NS->{$self} and defined $NS->{$self}{" self"}
MC/DC50%1/2
exists $NS->{$self} and defined $NS->{$self}{" self"}
exists $NS->{$self}
defined $NS->{$self}{" self"}
Truth table66%2/3
A and B
A= exists $NS->{$self}B= defined $NS->{$self}{" self"}
| |||||||||||||||||||||||||||||||||||||||||
| 58 | not exists $NS->{$self} | ||||||||||||||||||||||||||||||||||||||||
| 59 | or not defined $NS->{$self}->{' self'} | ||||||||||||||||||||||||||||||||||||||||
| 60 | ) | ||||||||||||||||||||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||||||||||||||||||||
| 62 | 2 | $NS->{$self} = { | |||||||||||||||||||||||||||||||||||||||
| 63 | ' self' => $self | ||||||||||||||||||||||||||||||||||||||||
| 64 | }; | ||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | weaken $NS->{$self}->{' self'}; | |||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||
| 68 | 6 | $NS->{$self}->{$name}; | |||||||||||||||||||||||||||||||||||||||
| 69 | 2 | }; | |||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||
| 72 | sub get_protected_variable($$) | ||||||||||||||||||||||||||||||||||||||||
| 73 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_protected_variable: called CC=1 SCAR=0.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | my( $package, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||
| 76 | 14 | ▶ | return sub: lvalue | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=23.7
| |||||||||||||||||||||||||||||||||||||||||
| 77 | { | ||||||||||||||||||||||||||||||||||||||||
| 78 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 79 | 14 | ▶ | if( | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $NS->{$self} and defined $NS->{$self}{" self"}
MC/DC0%0/2
exists $NS->{$self} and defined $NS->{$self}{" self"}
exists $NS->{$self}
defined $NS->{$self}{" self"}
Truth table33%1/3
A and B
A= exists $NS->{$self}B= defined $NS->{$self}{" self"}
| |||||||||||||||||||||||||||||||||||||||||
| 80 | not exists $NS->{$self} | ||||||||||||||||||||||||||||||||||||||||
| 81 | or not defined $NS->{$self}->{' self'} | ||||||||||||||||||||||||||||||||||||||||
| 82 | ) | ||||||||||||||||||||||||||||||||||||||||
| 83 | { | ||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $NS->{$self} = { | |||||||||||||||||||||||||||||||||||||||
| 85 | ' self' => $self | ||||||||||||||||||||||||||||||||||||||||
| 86 | }; | ||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | weaken $NS->{$self}->{' self'}; | |||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||
| 90 | 14 | ▶ | croak sprintf( | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$name || 'undefined'
$package || 'undefined'
caller() || 'undefined'
MC/DC0%0/1
$name || 'undefined'
$name
MC/DC0%0/1
$package || 'undefined'
$package
MC/DC0%0/1
caller() || 'undefined'
caller()
Truth table50%1/2
A
A= $name
Truth table50%1/2
A
A= $package
Truth table50%1/2
A
A= caller()
| |||||||||||||||||||||||||||||||||||||||||
| 91 | "Access violation: protected variable %s of %s available only to class or subclasses, but not %s." | ||||||||||||||||||||||||||||||||||||||||
| 92 | , $name || 'undefined' | ||||||||||||||||||||||||||||||||||||||||
| 93 | , $package || 'undefined' | ||||||||||||||||||||||||||||||||||||||||
| 94 | , caller() || 'undefined' ) if not caller()->isa($package); | ||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||
| 96 | 8 | $NS->{$self}->{$name}; | |||||||||||||||||||||||||||||||||||||||
| 97 | 2 | }; | |||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||
| 100 | sub get_private_variable($$) | ||||||||||||||||||||||||||||||||||||||||
| 101 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_private_variable: called CC=1 SCAR=0.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||
| 102 | 2 | my( $package, $name ) = @_; | |||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||
| 104 | 14 | ▶ | return sub: lvalue | ||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=23.7
| |||||||||||||||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||||||||||||||
| 106 | 14 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||
| 107 | 14 | ▶ | if( | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $NS->{$self} and defined $NS->{$self}{" self"}
MC/DC0%0/2
exists $NS->{$self} and defined $NS->{$self}{" self"}
exists $NS->{$self}
defined $NS->{$self}{" self"}
Truth table33%1/3
A and B
A= exists $NS->{$self}B= defined $NS->{$self}{" self"}
| |||||||||||||||||||||||||||||||||||||||||
| 108 | not exists $NS->{$self} | ||||||||||||||||||||||||||||||||||||||||
| 109 | or not defined $NS->{$self}->{' self'} | ||||||||||||||||||||||||||||||||||||||||
| 110 | ) | ||||||||||||||||||||||||||||||||||||||||
| 111 | { | ||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $NS->{$self} = { | |||||||||||||||||||||||||||||||||||||||
| 113 | ' self' => $self | ||||||||||||||||||||||||||||||||||||||||
| 114 | }; | ||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | weaken $NS->{$self}->{' self'}; | |||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||
| 118 | 14 | ▶ | croak sprintf( | ||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$name || 'undefined'
$package || 'undefined'
caller() || 'undefined'
MC/DC0%0/1
$name || 'undefined'
$name
MC/DC0%0/1
$package || 'undefined'
$package
MC/DC0%0/1
caller() || 'undefined'
caller()
Truth table50%1/2
A
A= $name
Truth table50%1/2
A
A= $package
Truth table50%1/2
A
A= caller()
| |||||||||||||||||||||||||||||||||||||||||
| 119 | "Access violation: private variable %s of %s available only to class itself, not %s." | ||||||||||||||||||||||||||||||||||||||||
| 120 | , $name || 'undefined' | ||||||||||||||||||||||||||||||||||||||||
| 121 | , $package || 'undefined' | ||||||||||||||||||||||||||||||||||||||||
| 122 | , caller() || 'undefined' ) if caller() ne $package; | ||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||
| 124 | 6 | $NS->{$self}->{$name}; | |||||||||||||||||||||||||||||||||||||||
| 125 | 2 | }; | |||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||
| 129 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||
| 130 | __END__ | ||||||||||||||||||||||||||||||||||||||||