| 1 | package perl5i::1::Meta::Instance; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | no if $] > 5.018000, warnings => 'experimental::smartmatch'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | require Scalar::Util; | |||||||||||||||||||||||||||
| 8 | 1 | require overload; | |||||||||||||||||||||||||||
| 9 | 1 | require Carp; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use perl5i::1::autobox; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use parent qw(perl5i::1::Meta); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | sub class { | ||||||||||||||||||||||||||||
| 16 | 0 | ▶ | return ref ${$_[0]}; | ||||||||||||||||||||||||||
|
Subroutine
class: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | sub reftype { | ||||||||||||||||||||||||||||
| 20 | 0 | ▶ | return Scalar::Util::reftype(${$_[0]}); | ||||||||||||||||||||||||||
|
Subroutine
reftype: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | # Only instances can be tainted | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | # Returns the code which will run when the object is used as a string | ||||||||||||||||||||||||||||
| 27 | my $has_string_overload = sub { | ||||||||||||||||||||||||||||
| 28 | 0 | ▶ | return overload::Method(${$_[0]}, q[""]) || overload::Method(${$_[0]}, q[0+]) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Condition0%0/3
overload::Method(${$_[0];}, '""') || overload::Method(${$_[0];}, '0+')
MC/DC0%0/2
overload::Method(${$_[0];}, '""') || overload::Method(${$_[0];}, '0+')
overload::Method(${$_[0];}, '""')
overload::Method(${$_[0];}, '0+')
Truth table0%0/3
A || B
A= overload::Method(${$_[0];}, '""')B= overload::Method(${$_[0];}, '0+')
| |||||||||||||||||||||||||||||
| 29 | 1 | }; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | sub is_tainted { | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | my $code; | ||||||||||||||||||||||||||
|
Subroutine
is_tainted: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | ▶ | if( $code = $_[0]->$has_string_overload ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 35 | 0 | require Taint::Util; | |||||||||||||||||||||||||||
| 36 | 0 | return Taint::Util::tainted( $code->(${$_[0]}) ); | |||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||
| 38 | else { | ||||||||||||||||||||||||||||
| 39 | 0 | return 0; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 0 | die "Never should be reached"; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | sub taint { | ||||||||||||||||||||||||||||
| 47 | 0 | ▶ | if( $_[0]->$has_string_overload ) { | ||||||||||||||||||||||||||
|
Subroutine
taint: not called CC=3 SCAR=24.8
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 0 | ▶ | Carp::croak "Untainted overloaded objects cannot normally be made tainted" if | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | !$_[0]->is_tainted; | ||||||||||||||||||||||||||||
| 50 | 0 | return 1; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | else { | ||||||||||||||||||||||||||||
| 53 | 0 | Carp::croak "Only scalars can normally be made tainted"; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | Carp::confess "Should not be reached"; | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | sub untaint { | ||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if( $_[0]->$has_string_overload && $_[0]->is_tainted ) { | ||||||||||||||||||||||||||
|
Subroutine
untaint: not called CC=3 SCAR=24.8
Pod
undocumented
Branch: 1 branch
Condition0%0/3
$_[0]->$has_string_overload and $_[0]->is_tainted
MC/DC0%0/2
$_[0]->$has_string_overload and $_[0]->is_tainted
$_[0]->$has_string_overload
$_[0]->is_tainted
Truth table0%0/3
A and B
A= $_[0]->$has_string_overloadB= $_[0]->is_tainted
| |||||||||||||||||||||||||||||
| 62 | 0 | Carp::croak "Tainted overloaded objects cannot normally be untainted"; | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | else { | ||||||||||||||||||||||||||||
| 65 | 0 | return 1; | |||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 0 | Carp::confess "Should never be reached"; | |||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | sub checksum { | ||||||||||||||||||||||||||||
| 73 | 0 | ▶ | my( $thing, %args ) = @_; | ||||||||||||||||||||||||||
|
Subroutine
checksum: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 0 | my $algorithms = [qw(sha1 md5)]; | |||||||||||||||||||||||||||
| 76 | 0 | ▶ | $args{algorithm} //= 'sha1'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{"algorithm"} //= "sha1"
MC/DC0%0/1
$args{"algorithm"} //= "sha1"
$args{"algorithm"}
Truth table0%0/2
A
A= $args{"algorithm"}
| |||||||||||||||||||||||||||||
| 77 | 0 | ▶ | $args{algorithm} ~~ $algorithms or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 78 | 0 | Carp::croak("algorithm must be @{[ $algorithms->join(' or ' ) ]}"); | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 0 | my $algorithm2module = { sha1 => "Digest::SHA", md5 => "Digest::MD5" }; | |||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | my $format = [qw(hex base64 binary)]; | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | $args{format} //= 'hex'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{"format"} //= "hex"
MC/DC0%0/1
$args{"format"} //= "hex"
$args{"format"}
Truth table0%0/2
A
A= $args{"format"}
| |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | $args{format} ~~ $format or | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | 0 | Carp::croak("format must be @{[ $format->join(' or ') ]}"); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 0 | my %prefix = ( hex => 'hex', base64 => 'b64', binary => undef ); | |||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | 0 | my $module = $algorithm2module->{ $args{algorithm} }; | |||||||||||||||||||||||||||
| 90 | 0 | ▶ | my $digest = defined $prefix{ $args{format} } ? $prefix{ $args{format} } . 'digest' : 'digest'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | 0 | Module::Load::load($module); | |||||||||||||||||||||||||||
| 93 | 0 | my $digestor = $module->new; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | require Data::Dumper; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | my $d = Data::Dumper->new( [ ${$thing} ] ); | |||||||||||||||||||||||||||
| 98 | 0 | $d->Deparse(1)->Terse(1)->Sortkeys(1)->Indent(0); | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | $digestor->add( $d->Dump ); | |||||||||||||||||||||||||||
| 101 | 0 | return $digestor->$digest; | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 1 | 1; | |||||||||||||||||||||||||||