| 1 | package Type::Guess::Role::Tiny; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use MooX::ClassAttribute; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Scalar::Util qw(looks_like_number); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Type::Tiny; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Types::Standard qw( Int Num Str ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 0 | ▶ | has "name" => ( is => "rw", default => sub { "" } ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 0 | ▶ | has "type_tiny" => ( is => "rw", default => sub { Str } ); # whats this for? | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | 0 | ▶ | class_has "types" => ( is => "rw", default => sub { [ Int, Num, Str, ] }); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | # print $class_opts; | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | 3 | our $class_opts = { tolerance => 0, skip_empty => 1, encoding => "", types => [ Int, Num, Str, ] }; | |||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | 105 | ▶ | sub class_opts { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
class_opts: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 105 | my ($class, $opt, $val) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 21 | 105 | ▶ | die sprintf "Invalid option %s\n" unless exists $class_opts->{$opt}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 105 | ▶ | $class_opts->{$opt} = $val if defined $val; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | 105 | return $class_opts->{$opt} | |||||||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | 38 | ▶ | around "new" => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=18.0
| |||||||||||||||||||||||||||||||||||||||||||
| 27 | 38 | my $orig = shift; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 38 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 38 | ▶ | if (scalar @_ > 1 && !ref $_[0] && ref $_[-1]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
scalar @_ > 1 and not ref $_[0] and ref $_[-1]
scalar @_ > 1 and not ref $_[0]
MC/DC66%2/3
scalar @_ > 1 and not ref $_[0] and ref $_[-1]
scalar @_ > 1
not ref $_[0]
ref $_[-1]
Truth table75%3/4
A and not(B) and C
A= scalar @_ > 1B= not ref $_[0]C= ref $_[-1]
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 6 | my $opts = pop @_; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 6 | for (keys $opts->%*) { | |||||||||||||||||||||||||||||||||||||||||
| 32 | 6 | ▶ | $self->class_opts($_, $opts->{$_}) if $class_opts->{$_}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||
| 35 | 38 | my $ret = $orig->($self, @_); | |||||||||||||||||||||||||||||||||||||||||
| 36 | 38 | return $ret | |||||||||||||||||||||||||||||||||||||||||
| 37 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 3 | our $types = [ Int, Num, Str, ]; | |||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 20 | ▶ | sub _type { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_type: called CC=7 SCAR=19.9
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 20 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | my @vals = | ||||||||||||||||||||||||||||||||||||||||||
| 45 | 82 | ▶ | map { looks_like_number($_) && int($_) == $_ ? int($_) : $_ } | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
&looks_like_number($_) and int $_ == $_
MC/DC100%2/2
&looks_like_number($_) and int $_ == $_
&looks_like_number($_)
int $_ == $_
Truth table100%3/3
A and B
A= &looks_like_number($_)B= int $_ == $_
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 20 | map { s/(\d\.*\d*)%$/$1/r } | |||||||||||||||||||||||||||||||||||||||||
| 47 | @_; | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | 20 | my $tot = scalar @vals; | |||||||||||||||||||||||||||||||||||||||||
| 50 | 20 | for ($class->class_opts("types")->@*) { | |||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||
| 52 | 42 | ▶ | my $tiny_type = ref $_ ? $_ : eval $_ || eval '$' . $_; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
eval $_ or eval '$' . $_
MC/DC0%0/2
eval $_ or eval '$' . $_
eval $_
eval '$' . $_
Truth table0%0/3
A or B
A= eval $_B= eval '$' . $_
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||
| 54 | 42 | my $ok = scalar $tiny_type->grep(@vals); | |||||||||||||||||||||||||||||||||||||||||
| 55 | 42 | ▶ | if ($ok / $tot >= (1 - $class->tolerance)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | 20 | return $tiny_type | |||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||