| 1 | package Validation::Class::Base; | ||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||
| 3 | 56 | $Validation::Class::Base::VERSION = '7.10_01'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 56 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 56 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 56 | our $VERSION = '7.10_01'; # VERSION | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 56 | ▶ | use Exporter (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 56 | ▶ | use Carp 'confess'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 56 | our @ISA = qw(Exporter); | |||||||||||||||||||||||||||
| 15 | 56 | our @EXPORT = qw( | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | has | ||||||||||||||||||||||||||||
| 18 | hold | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | sub has { | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2184 | ▶ | my ($attrs, $default) = @_; | ||||||||||||||||||||||||||
|
Subroutine
has: called CC=8 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 2184 | ▶ | return unless $attrs; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 2184 | ▶ | confess "Error creating accessor, default must be a coderef or constant" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $default and ref $default ne "CODE"
MC/DC0%0/2
ref $default and ref $default ne "CODE"
ref $default
ref $default ne "CODE"
Truth table66%2/3
A and B
A= ref $defaultB= ref $default ne "CODE"
| |||||||||||||||||||||||||||||
| 29 | if ref $default && ref $default ne 'CODE'; | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 2184 | ▶ | $attrs = [$attrs] unless ref $attrs eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 2184 | for my $attr (@$attrs) { | |||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 2184 | ▶ | confess "Error creating accessor '$attr', name has invalid characters" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | unless $attr =~ /^[a-zA-Z_]\w*$/; | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 2184 | my $code ; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 2184 | ▶ | if (defined $default) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | $code = sub { | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 2052 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | 1977 | ▶ | return $_[0]->{$attr} if exists $_[0]->{$attr}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | 380 | ▶ | return $_[0]->{$attr} = ref $default eq 'CODE' ? | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | $default->($_[0]) : $default; | ||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | 75 | $_[0]->{$attr} = $_[1]; $_[0]; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 560 | }; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | else { | ||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | $code = sub { | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 1352 | ▶ | return $_[0]->{$attr} if @_ == 1; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 15 | $_[0]->{$attr} = $_[1]; $_[0]; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 1624 | }; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 56 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 67 | 56 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 2184 | my $class = caller(0); | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 2184 | *{"$class\::$attr"} = $code; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | sub hold { | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 560 | ▶ | my ($attrs, $default) = @_; | ||||||||||||||||||||||||||
|
Subroutine
hold: called CC=6 SCAR=18.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 560 | ▶ | return unless $attrs; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 560 | ▶ | confess "Error creating accessor, default is required and must be a coderef" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | if ref $default ne 'CODE'; | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | 560 | ▶ | $attrs = [$attrs] unless ref $attrs eq 'ARRAY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 560 | for my $attr (@$attrs) { | |||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 560 | ▶ | confess "Error creating accessor '$attr', name has invalid characters" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | unless $attr =~ /^[a-zA-Z_]\w*$/; | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 560 | my $code ; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | $code = sub { | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 14046 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.4
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 14046 | ▶ | return $_[0]->{$attr} if exists $_[0]->{$attr}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | 126 | return $_[0]->{$attr} = $default->($_[0]); | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | # values are read-only cannot be changed | ||||||||||||||||||||||||||||
| 103 | 0 | confess "Error attempting to modify the read-only attribute ($attr)"; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 560 | }; | |||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 56 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 108 | 56 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 560 | my $class = caller(0); | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 560 | *{"$class\::$attr"} = $code; | |||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | sub import { | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | 112 | ▶ | strict->import; | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 121 | 112 | warnings->import; | |||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 112 | __PACKAGE__->export_to_level(1, @_); | |||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 56 | 1; | |||||||||||||||||||||||||||