| 1 | package Type::Tiny::Bitfield; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use 5.008001; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | $Type::Tiny::Bitfield::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 4 | $Type::Tiny::Bitfield::VERSION = '2.010001'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | $Type::Tiny::Bitfield::VERSION =~ tr/_//d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 14 | ▶ | sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_croak: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | ▶ | use Exporter::Tiny 1.004001 (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 4 | ▶ | use Type::Tiny (); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 4 | ▶ | use Types::Common::Numeric qw( +PositiveOrZeroInt ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 4 | ▶ | use Eval::TypeTiny qw( eval_closure ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 4 | our @ISA = qw( Type::Tiny Exporter::Tiny ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 4 | __PACKAGE__->_install_overloads( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | q[+] => 'new_combined', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 42 | ▶ | sub _is_power_of_two { not $_[0] & $_[0]-1 } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_power_of_two: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 6 | ▶ | sub _exporter_fail { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exporter_fail: called CC=7 SCAR=21.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 6 | my ( $class, $type_name, $args, $globals ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 6 | my $caller = $globals->{into}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 6 | my %values = %$args; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 6 | ▶ | /^[-]/ && delete( $values{$_} ) for keys %values; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 6 | my $type = $class->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | name => $type_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | values => \%values, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | coercion => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | $INC{'Type/Registry.pm'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | ? 'Type::Registry'->for_class( $caller )->add_type( $type, $type_name ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | : ( $Type::Registry::DELAYED{$caller}{$type_name} = $type ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 4 | ▶ | unless( ref($caller) or $caller eq '-lexical' or $globals->{'lexical'} ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
ref $caller or $caller eq "-lexical" or $globals->{"lexical"}
ref $caller or $caller eq "-lexical"
MC/DC0%0/3
ref $caller or $caller eq "-lexical" or $globals->{"lexical"}
ref $caller
$caller eq "-lexical"
$globals->{"lexical"}
Truth table25%1/4
A or B or C
A= ref $callerB= $caller eq "-lexical"C= $globals->{"lexical"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 4 | return map +( $_->{name} => $_->{code} ), @{ $type->exportables }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 27 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=15 SCAR=27.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 27 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | _croak | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | "Bitfield type constraints cannot have a parent constraint passed to the constructor" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 27 | ▶ | if exists $opts{parent}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | _croak | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | "Bitfield type constraints cannot have a constraint coderef passed to the constructor" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 26 | ▶ | if exists $opts{constraint}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | _croak | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | "Bitfield type constraints cannot have a inlining coderef passed to the constructor" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 25 | ▶ | if exists $opts{inlined}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | _croak "Need to supply hashref of values" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 24 | ▶ | unless exists $opts{values}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 23 | $opts{parent} = PositiveOrZeroInt; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 23 | for my $key ( keys %{ $opts{values} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 46 | ▶ | _croak "Not an all-caps name in a bitfield: $key" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | unless $key =~ /^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 21 | my $ALL = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 21 | my %already = (); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 21 | for my $value ( values %{ $opts{values} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 42 | ▶ | _croak "Not a positive power of 2 in a bitfield: $value" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
is_PositiveOrZeroInt($value) and _is_power_of_two($value)
MC/DC50%1/2
is_PositiveOrZeroInt($value) and _is_power_of_two($value)
is_PositiveOrZeroInt($value)
_is_power_of_two($value)
Truth table66%2/3
A and B
A= is_PositiveOrZeroInt($value)B= _is_power_of_two($value)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | unless is_PositiveOrZeroInt( $value ) && _is_power_of_two( $value ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | _croak "Duplicate value in a bitfield: $value" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 40 | ▶ | if $already{$value}++; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 39 | $ALL |= ( 0 + $value ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 18 | $opts{ALL} = $ALL; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 92 | ▶ | $opts{constraint} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 92 | not shift() & ~$ALL; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 18 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 18 | ▶ | if ( defined $opts{coercion} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $opts{"coercion"} and not ref $opts{"coercion"} and 1 eq $opts{"coercion"}
defined $opts{"coercion"} and not ref $opts{"coercion"}
MC/DC33%1/3
defined $opts{"coercion"} and not ref $opts{"coercion"} and 1 eq $opts{"coercion"}
defined $opts{"coercion"}
not ref $opts{"coercion"}
1 eq $opts{"coercion"}
Truth table50%2/4
A and not(B) and C
A= defined $opts{"coercion"}B= not ref $opts{"coercion"}C= 1 eq $opts{"coercion"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | and !ref $opts{coercion} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | and 1 eq $opts{coercion} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 12 | delete $opts{coercion}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 11 | ▶ | $opts{_build_coercion} = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 11 | require Types::Standard; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 11 | my $c = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 11 | my $t = $c->type_constraint; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 11 | $c->add_type_coercions( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | Types::Standard::Str(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | $t->_stringy_coercion, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 12 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } #/ if ( defined $opts{coercion...}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 18 | return $proto->SUPER::new( %opts ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } #/ sub new | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 10 | ▶ | sub new_combined { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new_combined: called CC=10 SCAR=23.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 10 | my ( $self, $other, $swap ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 10 | ▶ | Scalar::Util::blessed( $self ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%6/9
builtin::blessed($self) and $self->isa(__PACKAGE__) and builtin::blessed($other) and $other->isa(__PACKAGE__)
builtin::blessed($self) and $self->isa(__PACKAGE__) and builtin::blessed($other)
builtin::blessed($self) and $self->isa(__PACKAGE__)
MC/DC50%2/4
builtin::blessed($self) and $self->isa(__PACKAGE__) and builtin::blessed($other) and $other->isa(__PACKAGE__)
builtin::blessed($self)
$self->isa(__PACKAGE__)
builtin::blessed($other)
$other->isa(__PACKAGE__)
Truth table60%3/5
A and B and C and D
A= builtin::blessed($self)B= $self->isa(__PACKAGE__)C= builtin::blessed($other)D= $other->isa(__PACKAGE__)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | && $self->isa( __PACKAGE__ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | && Scalar::Util::blessed( $other ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | && $other->isa( __PACKAGE__ ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | or _croak( "Bad overloaded operation" ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 6 | ▶ | ( $other, $self ) = ( $self, $other ) if $swap; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 6 | for my $k ( keys %{ $self->values } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | _croak "Conflicting value: $k" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 10 | ▶ | if exists $other->values->{$k}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 5 | my %all_values = ( %{ $self->values }, %{ $other->values } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 5 | ▶ | return ref( $self )->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$self->has_coercion or $other->has_coercion
MC/DC100%2/2
$self->has_coercion or $other->has_coercion
$self->has_coercion
$other->has_coercion
Truth table100%3/3
A or B
A= $self->has_coercionB= $other->has_coercion
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | display_name => sprintf( '%s+%s', "$self", "$other" ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | values => \%all_values, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | ( $self->has_coercion || $other->has_coercion ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | ? ( coercion => 1 ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | : (), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 64 | ▶ | sub values { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
values: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 64 | $_[0]{values}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 18 | ▶ | sub _lockdown { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_lockdown: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 18 | my ( $self, $callback ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 18 | $callback->( $self->{values} ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 5 | ▶ | sub exportables { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
exportables: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 5 | my ( $self, $base_name ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 5 | ▶ | if ( not $self->is_anon ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 5 | ▶ | $base_name ||= $self->name; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$base_name ||= $self->name
MC/DC0%0/2
$base_name ||= $self->name
$base_name
$self->name
Truth table33%1/3
A ||= B
A= $base_nameB= $self->name
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 5 | my $exportables = $self->SUPER::exportables( $base_name ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 5 | require Eval::TypeTiny; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 5 | require B; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 5 | for my $key ( keys %{ $self->values } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 17 | my $value = $self->values->{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 17 | push @$exportables, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | name => uc( sprintf '%s_%s', $base_name, $key ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | tags => [ 'constants' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | code => Eval::TypeTiny::eval_closure( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | source => sprintf( 'sub () { %d }', $value ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | environment => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 5 | my $weak = $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 5 | require Scalar::Util; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 5 | Scalar::Util::weaken( $weak ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | push @$exportables, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | name => sprintf( '%s_to_Str', $base_name ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | tags => [ 'from' ], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 1 | ▶ | code => sub { $weak->to_string( @_ ) }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 5 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 5 | return $exportables; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 1 | ▶ | sub constant_names { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
constant_names: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 4 | return map { $_->{name} } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 9 | grep { my $tags = $_->{tags}; grep $_ eq 'constants', @$tags; } | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | ▶ | @{ $self->exportables || [] }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->exportables || []
MC/DC0%0/1
$self->exportables || []
$self->exportables
Truth table50%1/2
A
A= $self->exportables
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 126 | ▶ | sub can_be_inlined { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can_be_inlined: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 126 | !!1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 221 | ▶ | sub inline_check { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inline_check: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 221 | my ( $self, $var ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | return sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | '( %s and not %s & ~%d )', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | PositiveOrZeroInt->inline_check( $var ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | $var, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | $self->{ALL}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 221 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 12 | ▶ | sub _stringy_coercion { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_stringy_coercion: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 12 | my ( $self, $varname ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 12 | ▶ | $varname ||= '$_'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$varname ||= "\$_"
MC/DC100%1/1
$varname ||= "\$_"
$varname
Truth table100%2/2
A
A= $varname
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 12 | my %vals = %{ $self->values }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 12 | my $pfx = uc( "$self" ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 12 | my $pfxl = length $pfx; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | my $hash = sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | '( %s )', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | join( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | q{, }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 12 | map sprintf( '%s => %d', B::perlstring($_), $vals{$_} ), | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | sort keys %vals, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 12 | return qq{do { my \$bits = 0; my \%lookup = $hash; for my \$tok ( grep /\\w/, split /[\\s|+]+/, uc( $varname ) ) { if ( substr( \$tok, 0, $pfxl) eq "$pfx" ) { \$tok = substr( \$tok, $pfxl ); \$tok =~ s/^_//; } if ( exists \$lookup{\$tok} ) { \$bits |= \$lookup{\$tok}; next; } require Carp; Carp::carp("Unknown token: \$tok"); } \$bits; }}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 1 | ▶ | sub from_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
from_string: called CC=2 SCAR=7.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 1 | my ( $self, $str ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 1 | ▶ | $self->{from_string} ||= eval_closure( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"from_string"} ||= eval_closure("environment", scalar {}, "source", sprintf("sub { my \$STR = shift; %s }", $self->_stringy_coercion("\$STR")))
MC/DC0%0/2
$self->{"from_string"} ||= eval_closure("environment", scalar {}, "source", sprintf("sub { my \$STR = shift; %s }", $self->_stringy_coercion("\$STR")))
$self->{"from_string"}
eval_closure("environment", scalar {}, "source", sprintf("sub { my \$STR = shift; %s }", $self->_stringy_coercion("\$STR")))
Truth table33%1/3
A ||= B
A= $self->{"from_string"}B= eval_closure("environment", scalar {}, "source", sprintf("sub { my \$STR = shift; %s }", $self->_stringy_coercion("\$STR")))
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | environment => {}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | source => sprintf( 'sub { my $STR = shift; %s }', $self->_stringy_coercion( '$STR' ) ), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 1 | $self->{from_string}->( $str ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 6 | ▶ | sub to_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 6 | my ( $self, $int ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 6 | ▶ | $self->check( $int ) or return undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 4 | my %values = %{ $self->values }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 4 | ▶ | $self->{all_names} ||= [ sort { $values{$a} <=> $values{$b} } keys %values ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"all_names"} ||= [(sort {$values{$a} <=> $values{$b};} keys %values)]
MC/DC100%1/1
$self->{"all_names"} ||= [(sort {$values{$a} <=> $values{$b};} keys %values)]
$self->{"all_names"}
Truth table100%2/2
A
A= $self->{"all_names"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 4 | $int += 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 4 | my @names; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 4 | for my $n ( @{ $self->{all_names} } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | 16 | ▶ | push @names, $n if $int & $values{$n}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 4 | return join q{|}, @names; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 5 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 5 | our $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 5 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 5 | my ( $m ) = ( $AUTOLOAD =~ /::(\w+)$/ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 5 | ▶ | return if $m eq 'DESTROY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 5 | ▶ | if ( ref $self and exists $self->{values}{$m} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $self and exists $self->{"values"}{$m}
MC/DC50%1/2
ref $self and exists $self->{"values"}{$m}
ref $self
exists $self->{"values"}{$m}
Truth table66%2/3
A and B
A= ref $selfB= exists $self->{"values"}{$m}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 4 | return 0 + $self->{values}{$m}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 1 | local $Type::Tiny::AUTOLOAD = $AUTOLOAD; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 1 | return $self->SUPER::AUTOLOAD( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | 502 | ▶ | sub can { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
can: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 502 | my ( $self, $m ) = ( shift, @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 502 | ▶ | if ( ref $self and exists $self->{values}{$m} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $self and exists $self->{"values"}{$m}
MC/DC50%1/2
ref $self and exists $self->{"values"}{$m}
ref $self
exists $self->{"values"}{$m}
Truth table66%2/3
A and B
A= ref $selfB= exists $self->{"values"}{$m}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 2 | ▶ | return sub () { 0 + $self->{values}{$m} }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 500 | return $self->SUPER::can( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||