| 1 | package File::DataClass::Types; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use File::DataClass::IO qw( io ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use Scalar::Util qw( blessed dualvar ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use Type::Library -base, -declare => | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | qw( Cache DummyClass HashRefOfBools Lock | ||||||||||||||||||||||||||||
| 10 | 6 | OctalNum Result Path Directory File ); | |||||||||||||||||||||||||||
| 11 | 6 | ▶ | use Type::Utils qw( as coerce extends from | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 6 | message subtype via where ); | |||||||||||||||||||||||||||
| 13 | 6 | ▶ | use Unexpected::Functions qw( inflate_message ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 6 | ▶ | use namespace::clean -except => 'meta'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 6 | ▶ | BEGIN { extends q(Unexpected::Types) }; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | # Private functions | ||||||||||||||||||||||||||||
| 20 | 4 | ▶ | my $_coercion_for_octalnum = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 21 | 4 | ▶ | my $x = shift; length $x or return $x; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | ▶ | $x =~ m{ [^0-7] }mx and return $x; $x =~ s{ \A 0 }{}gmx; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 1 | return dualvar oct "${x}", "0${x}" | |||||||||||||||||||||||||||
| 26 | 6 | }; | |||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 15 | ▶ | my $_constraint_for_octalnum = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 29 | 15 | ▶ | my $x = shift; length $x or return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 12 | ▶ | $x =~ m{ [^0-7] }mx and return 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 6 | ▶ | return ($x < 8) || (oct "${x}" == $x + 0) ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$x < 8 or oct "$x" == $x + 0
MC/DC100%2/2
$x < 8 or oct "$x" == $x + 0
$x < 8
oct "$x" == $x + 0
Truth table100%3/3
A or B
A= $x < 8B= oct "$x" == $x + 0
| |||||||||||||||||||||||||||||
| 34 | 6 | }; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 2 | ▶ | my $_exception_message_for_object_reference = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 37 | 2 | return inflate_message( 'String [_1] is not an object reference', $_[ 0 ] ); | |||||||||||||||||||||||||||
| 38 | 6 | }; | |||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 3 | ▶ | my $_exception_message_for_cache = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 41 | 3 | ▶ | blessed $_[ 0 ] and return inflate_message | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | ( 'Object [_1] is not of class File::DataClass::Cache', blessed $_[ 0 ] ); | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 1 | return $_exception_message_for_object_reference->( $_[ 0 ] ); | |||||||||||||||||||||||||||
| 45 | 6 | }; | |||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 3 | ▶ | my $_exception_message_for_lock = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 48 | 3 | ▶ | blessed $_[ 0 ] and return inflate_message | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | ( 'Object [_1] is missing set / reset methods', blessed $_[ 0 ] ); | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 1 | return $_exception_message_for_object_reference->( $_[ 0 ] ); | |||||||||||||||||||||||||||
| 52 | 6 | }; | |||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 2 | ▶ | my $_exception_message_for_path = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||
| 55 | 2 | ▶ | blessed $_[ 0 ] and return inflate_message | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | ( 'Object [_1] is not of class File::DataClass::IO', blessed $_[ 0 ] ); | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | return $_exception_message_for_object_reference->( $_[ 0 ] ); | |||||||||||||||||||||||||||
| 59 | 6 | }; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 2 | ▶ | my $_exception_message_for_result = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=9.2
| |||||||||||||||||||||||||||||
| 62 | 2 | ▶ | blessed $_[ 0 ] and return inflate_message | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | ( 'Object [_1] is not of class File::DataClass::Result', blessed $_[ 0 ]); | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 0 | return $_exception_message_for_object_reference->( $_[ 0 ] ); | |||||||||||||||||||||||||||
| 66 | 6 | }; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | subtype Cache, as Object, | ||||||||||||||||||||||||||||
| 69 | 19 | ▶ | where { $_->isa( 'File::DataClass::Cache' ) or $_->isa( 'Class::Null' ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 3 | ▶ | message { $_exception_message_for_cache->( $_ ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | subtype DummyClass, as Str, | ||||||||||||||||||||||||||||
| 73 | 8 | ▶ | where { $_ eq 'none' }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 74 | 2 | ▶ | message { inflate_message( 'Dummy class [_1] is not "none"', $_ ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 6 | subtype HashRefOfBools, as HashRef; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | subtype Lock, as Object, | ||||||||||||||||||||||||||||
| 79 | 19 | ▶ | where { ($_->can( 'set' ) and $_->can( 'reset' ) ) | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=14.2
Branch: 1 branch
Condition33%1/3
$_->can("set") and $_->can("reset")
MC/DC0%0/2
$_->can("set") and $_->can("reset")
$_->can("set")
$_->can("reset")
Truth table33%1/3
A and B
A= $_->can("set")B= $_->can("reset")
| |||||||||||||||||||||||||||||
| 80 | or $_->isa( 'Class::Null' ) }, | ||||||||||||||||||||||||||||
| 81 | 3 | ▶ | message { $_exception_message_for_lock->( $_ ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | subtype OctalNum, as Str, | ||||||||||||||||||||||||||||
| 84 | 15 | ▶ | where { $_constraint_for_octalnum->( $_ ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 85 | 7 | ▶ | message { inflate_message( 'String [_1] is not an octal number', $_ ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | subtype Path, as Object, | ||||||||||||||||||||||||||||
| 88 | 40 | ▶ | where { $_->isa( 'File::DataClass::IO' ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 89 | 2 | ▶ | message { $_exception_message_for_path->( $_ ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | subtype Result, as Object, | ||||||||||||||||||||||||||||
| 92 | 4 | ▶ | where { $_->isa( 'File::DataClass::Result' ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 93 | 2 | ▶ | message { $_exception_message_for_result->( $_ ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | subtype Directory, as Path, | ||||||||||||||||||||||||||||
| 97 | 19 | ▶ | where { $_->exists and $_->is_dir }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | message { inflate_message( 'Path [_1] is not a directory', $_ ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | subtype File, as Path, | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | where { $_->exists and $_->is_file }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | 0 | ▶ | message { inflate_message( 'Path [_1] is not a file', $_ ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | coerce HashRefOfBools, from ArrayRef, | ||||||||||||||||||||||||||||
| 105 | 0 | ▶ | via { my %hash = map { $_ => 1 } @{ $_ }; return \%hash; }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=4.1
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | 4 | ▶ | coerce OctalNum, from Str, via { $_coercion_for_octalnum->( $_ ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | coerce Directory, | ||||||||||||||||||||||||||||
| 110 | 0 | ▶ | from ArrayRef, via { io( $_ ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 111 | 0 | ▶ | from CodeRef, via { io( $_ ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 112 | 0 | ▶ | from HashRef, via { io( $_ ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 113 | 19 | ▶ | from Str, via { io( $_ ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 114 | 0 | ▶ | from Undef, via { io( $_ ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | coerce File, | ||||||||||||||||||||||||||||
| 117 | 0 | ▶ | from ArrayRef, via { io( $_ ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | from CodeRef, via { io( $_ ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 119 | 0 | ▶ | from HashRef, via { io( $_ ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 120 | 0 | ▶ | from Str, via { io( $_ ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 121 | 0 | ▶ | from Undef, via { io( $_ ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | coerce Path, | ||||||||||||||||||||||||||||
| 124 | 10 | ▶ | from ArrayRef, via { io( $_ ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 125 | 0 | ▶ | from CodeRef, via { io( $_ ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 126 | 0 | ▶ | from HashRef, via { io( $_ ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 127 | 7 | ▶ | from Str, via { io( $_ ) }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 128 | 1 | ▶ | from Undef, via { io( $_ ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 6 | 1; | |||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | __END__ | ||||||||||||||||||||||||||||