| 1 | package Type::Tiny::Class; | ||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 34 | ▶ | use 5.008001; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 34 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 34 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 34 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 34 | $Type::Tiny::Class::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||||||||||||||||||||
| 9 | 34 | $Type::Tiny::Class::VERSION = '2.010001'; | |||||||||||||||||||||||||||||||||||||||||||||
| 10 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 34 | $Type::Tiny::Class::VERSION =~ tr/_//d; | |||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 34 | ▶ | use Scalar::Util qw< blessed >; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_croak: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 34 | ▶ | use Exporter::Tiny 1.004001 (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 34 | ▶ | use Type::Tiny::ConstrainedObject (); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 34 | our @ISA = qw( Type::Tiny::ConstrainedObject Exporter::Tiny ); | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 3 | ▶ | sub _short_name { 'Class' } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_short_name: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | sub _exporter_fail { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_exporter_fail: called CC=7 SCAR=21.3
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 2 | my ( $class, $name, $opts, $globals ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | 2 | my $caller = $globals->{into}; | |||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | $opts->{name} = $name unless exists $opts->{name}; $opts->{name} =~ s/:://g; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | $opts->{class} = $name unless exists $opts->{class}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 2 | my $type = $class->new($opts); | |||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | $INC{'Type/Registry.pm'} | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | ? 'Type::Registry'->for_class( $caller )->add_type( $type ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 34 | : ( $Type::Registry::DELAYED{$caller}{$type->name} = $type ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | 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"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | return map +( $_->{name} => $_->{code} ), @{ $type->exportables }; | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 182 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 182 | my $proto = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | 182 | ▶ | return $proto->class->new( @_ ) if blessed $proto; # DWIM | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 179 | ▶ | my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 179 | ▶ | _croak "Need to supply class name" unless exists $opts{class}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 178 | if ( Type::Tiny::_USE_XS ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | my $xsub = | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 178 | Type::Tiny::XS::get_coderef_for( "InstanceOf[" . $opts{class} . "]" ); | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 178 | ▶ | $opts{compiled_type_constraint} = $xsub if $xsub; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | elsif ( Type::Tiny::_USE_MOUSE ) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 52 | require Mouse::Util::TypeConstraints; | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | my $maker = "Mouse::Util::TypeConstraints"->can( "generate_isa_predicate_for" ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 54 | $opts{compiled_type_constraint} = $maker->( $opts{class} ) if $maker; | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 178 | return $proto->SUPER::new( %opts ); | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | } #/ sub new | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 248 | ▶ | sub class { $_[0]{class} } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
class: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 670 | ▶ | sub inlined { $_[0]{inlined} ||= $_[0]->_build_inlined } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
inlined: called CC=2 SCAR=7.2
Pod
documented
Condition66%2/3
$_[0]{"inlined"} ||= $_[0]->_build_inlined
MC/DC0%0/2
$_[0]{"inlined"} ||= $_[0]->_build_inlined
$_[0]{"inlined"}
$_[0]->_build_inlined
Truth table66%2/3
A ||= B
A= $_[0]{"inlined"}B= $_[0]->_build_inlined
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 1229 | ▶ | sub has_inlined { !!1 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
has_inlined: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 2183 | ▶ | sub _is_null_constraint { 0 } | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_null_constraint: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 30 | ▶ | sub _build_constraint { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_constraint: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 30 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 69 | 30 | my $class = $self->class; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | 30 | ▶ | return sub { blessed( $_ ) and $_->isa( $class ) }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 113 | ▶ | sub _build_inlined { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_inlined: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 113 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 113 | my $class = $self->class; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 113 | my $xsub; | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | 113 | $xsub = Type::Tiny::XS::get_subname_for( "InstanceOf[$class]" ) | |||||||||||||||||||||||||||||||||||||||||||||
| 79 | if Type::Tiny::_USE_XS; | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 670 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 670 | my $var = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 83 | return | ||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 670 | ▶ | qq{do { use Scalar::Util (); Scalar::Util::blessed($var) and $var->isa(q[$class]) }} | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | if $Type::Tiny::AvoidCallbacks; | ||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 574 | ▶ | return "$xsub\($var\)" | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 87 | if $xsub; | ||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | qq{Scalar::Util::blessed($var) and $var->isa(q[$class])}; | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | 113 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 90 | } #/ sub _build_inlined | ||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | ▶ | sub _build_default_message { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_default_message: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 34 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | my $c = $self->class; | |||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | sprintf '%s did not pass type constraint (not isa %s)', | |||||||||||||||||||||||||||||||||||||||||||||
| 98 | Type::Tiny::_dd( $_[0] ), $c; | ||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | ▶ | if $self->is_anon; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | my $name = "$self"; | |||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | ▶ | return sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1 | sprintf '%s did not pass type constraint "%s" (not isa %s)', | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | Type::Tiny::_dd( $_[0] ), $name, $c; | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | } #/ sub _build_default_message | ||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | sub _instantiate_moose_type { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_instantiate_moose_type: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | my %opts = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | delete $opts{parent}; | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | delete $opts{constraint}; | |||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | delete $opts{inlined}; | |||||||||||||||||||||||||||||||||||||||||||||
| 114 | 0 | require Moose::Meta::TypeConstraint::Class; | |||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | return "Moose::Meta::TypeConstraint::Class" | |||||||||||||||||||||||||||||||||||||||||||||
| 116 | ->new( %opts, class => $self->class ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } #/ sub _instantiate_moose_type | ||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | sub plus_constructors { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
plus_constructors: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | ▶ | unless ( @_ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | require Types::Standard; | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | push @_, Types::Standard::HashRef(), "new"; | |||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | require B; | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | require Types::TypeTiny; | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my $class = B::perlstring( $self->class ); | |||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | my @r; | |||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | while ( @_ ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | my $source = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | ▶ | Types::TypeTiny::is_TypeTiny( $source ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 136 | or _croak "Expected type constraint; got $source"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | my $constructor = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | ▶ | Types::TypeTiny::is_StringLike( $constructor ) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 140 | or _croak "Expected string; got $constructor"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | push @r, $source, sprintf( '%s->%s($_)', $class, $constructor ); | |||||||||||||||||||||||||||||||||||||||||||||
| 143 | } #/ while ( @_ ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | return $self->plus_coercions( \@r ); | |||||||||||||||||||||||||||||||||||||||||||||
| 146 | } #/ sub plus_constructors | ||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 284 | ▶ | sub parent { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parent: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 284 | ▶ | $_[0]{parent} ||= $_[0]->_build_parent; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$_[0]{"parent"} ||= $_[0]->_build_parent
MC/DC0%0/2
$_[0]{"parent"} ||= $_[0]->_build_parent
$_[0]{"parent"}
$_[0]->_build_parent
Truth table66%2/3
A ||= B
A= $_[0]{"parent"}B= $_[0]->_build_parent
| |||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 88 | ▶ | sub _build_parent { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_parent: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 88 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | 88 | my $class = $self->class; | |||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # Some classes (I'm looking at you, Math::BigFloat) include a class in | ||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # their @ISA to inherit methods, but then override isa() to return false, | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # so that they don't appear to be a subclass. | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # In these cases, we don't want to list the parent class as a parent | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # type constraint. | ||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | my @isa = grep $class->isa( $_ ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 34 | ▶ | do { no strict "refs"; no warnings; @{"$class\::ISA"} }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 88 | ▶ | if ( @isa == 0 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 60 | require Types::Standard; | |||||||||||||||||||||||||||||||||||||||||||||
| 168 | 60 | return Types::Standard::Object(); | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 28 | ▶ | if ( @isa == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 24 | return ref( $self )->new( class => $isa[0] ); | |||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 174 | |||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 4 | require Type::Tiny::Intersection; | |||||||||||||||||||||||||||||||||||||||||||||
| 176 | 4 | "Type::Tiny::Intersection"->new( | |||||||||||||||||||||||||||||||||||||||||||||
| 177 | type_constraints => [ map ref( $self )->new( class => $_ ), @isa ], | ||||||||||||||||||||||||||||||||||||||||||||||
| 178 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 179 | } #/ sub _build_parent | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||
| 181 | *__get_linear_isa_dfs = | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 34 | eval { require mro } | |||||||||||||||||||||||||||||||||||||||||||||
| 183 | ? \&mro::get_linear_isa | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | ▶ | : sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=25.3
| |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 34 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | my $classname = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | my @lin = ( $classname ); | |||||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | my %stored; | |||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | foreach my $parent ( @{"$classname\::ISA"} ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | my $plin = __get_linear_isa_dfs( $parent ); | |||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | foreach ( @$plin ) { | |||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | ▶ | next if exists $stored{$_}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | push( @lin, $_ ); | |||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | $stored{$_} = 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | return \@lin; | |||||||||||||||||||||||||||||||||||||||||||||
| 201 | 34 | ▶ | }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | ▶ | sub validate_explain { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
validate_explain: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 205 | 1 | my ( $value, $varname ) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 206 | 1 | ▶ | $varname = '$_' unless defined $varname; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||
| 208 | 1 | ▶ | return undef if $self->check( $value ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 1 | ▶ | return ["Not a blessed reference"] unless blessed( $value ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 1 | my @isa = @{ __get_linear_isa_dfs( ref $value ) }; | |||||||||||||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 1 | ▶ | my $display_var = $varname eq q{$_} ? '' : sprintf( ' (in %s)', $varname ); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 1 | require Type::Utils; | |||||||||||||||||||||||||||||||||||||||||||||
| 216 | return [ | ||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | sprintf( '"%s" requires that the reference isa %s', $self, $self->class ), | |||||||||||||||||||||||||||||||||||||||||||||
| 218 | sprintf( | ||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 'The reference%s isa %s', $display_var, Type::Utils::english_list( @isa ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 220 | ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 221 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } #/ sub validate_explain | ||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 34 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||
| 226 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||