| 1 | 4 | ▶ | use 5.012; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||
| 5 | package Exporter::Almighty; | ||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||
| 7 | 4 | our $AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||||
| 8 | 4 | our $VERSION = '0.001004'; | |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use parent qw( Exporter::Tiny ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||
| 12 | 4 | my @builtins; | |||||||||||||||||||||||||||||
| 13 | 4 | ▶ | BEGIN { @builtins = qw( is_bool created_as_string created_as_number ) }; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 14 | 4 | ▶ | use if $] lt '5.036000', 'builtins::compat' => @builtins; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 15 | 4 | ▶ | use if $] ge '5.036000', 'builtin' => @builtins; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 16 | 4 | ▶ | no if $] ge '5.036000', 'warnings' => qw( experimental::builtin ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||
| 18 | 4 | ▶ | use B qw( perlstring ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 19 | 4 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 20 | 4 | ▶ | use Eval::TypeTiny qw( eval_closure set_subname ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 21 | 4 | ▶ | use Exporter::Tiny qw( mkopt ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 22 | 4 | ▶ | use Import::Into; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 23 | 4 | ▶ | use Module::Runtime qw( require_module module_notional_filename ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 24 | 4 | ▶ | use Type::Registry qw(); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 25 | 4 | use Types::Common qw( | |||||||||||||||||||||||||||||
| 26 | -sigs | ||||||||||||||||||||||||||||||
| 27 | -types | ||||||||||||||||||||||||||||||
| 28 | assert_Ref is_Ref | ||||||||||||||||||||||||||||||
| 29 | assert_ArrayRef is_ArrayRef | ||||||||||||||||||||||||||||||
| 30 | assert_HashRef is_HashRef | ||||||||||||||||||||||||||||||
| 31 | is_NonEmptySimpleStr | ||||||||||||||||||||||||||||||
| 32 | 4 | ▶ | ); | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||
| 34 | sub _exporter_validate_opts { | ||||||||||||||||||||||||||||||
| 35 | 2 | ▶ | my ( $me, $options ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
_exporter_validate_opts: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 36 | 2 | my $into = $options->{into}; | |||||||||||||||||||||||||||||
| 37 | 2 | my $setup = $options->{setup}; | |||||||||||||||||||||||||||||
| 38 | 2 | strict->import::into( $into ); | |||||||||||||||||||||||||||||
| 39 | 2 | warnings->import::into( $into ); | |||||||||||||||||||||||||||||
| 40 | 2 | $me->setup_for( $into, $setup ); | |||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||
| 43 | # Subclasses may wish to provide a subclass of Exporter::Tiny here. | ||||||||||||||||||||||||||||||
| 44 | sub base_exporter { | ||||||||||||||||||||||||||||||
| 45 | 8 | ▶ | return 'Exporter::Tiny'; | ||||||||||||||||||||||||||||
|
Subroutine
base_exporter: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||
| 48 | sub standard_package_variables { | ||||||||||||||||||||||||||||||
| 49 | 30 | ▶ | my ( $me, $into ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
standard_package_variables: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 50 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 51 | return ( | ||||||||||||||||||||||||||||||
| 52 | 30 | \@{"$into\::ISA"}, | |||||||||||||||||||||||||||||
| 53 | 30 | \@{"$into\::EXPORT"}, | |||||||||||||||||||||||||||||
| 54 | 30 | \@{"$into\::EXPORT_OK"}, | |||||||||||||||||||||||||||||
| 55 | 30 | \%{"$into\::EXPORT_TAGS"}, | |||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||
| 59 | 4 | signature_for setup_for => ( | |||||||||||||||||||||||||||||
| 60 | method => 1, | ||||||||||||||||||||||||||||||
| 61 | head => [ NonEmptySimpleStr ], | ||||||||||||||||||||||||||||||
| 62 | named => [ | ||||||||||||||||||||||||||||||
| 63 | tag => Optional[HashRef], | ||||||||||||||||||||||||||||||
| 64 | also => Optional[ArrayRef], | ||||||||||||||||||||||||||||||
| 65 | enum => Optional[HashRef[ArrayRef]], | ||||||||||||||||||||||||||||||
| 66 | class => Optional[ArrayRef], | ||||||||||||||||||||||||||||||
| 67 | role => Optional[ArrayRef], | ||||||||||||||||||||||||||||||
| 68 | duck => Optional[HashRef[ArrayRef]], | ||||||||||||||||||||||||||||||
| 69 | type => Optional[ArrayRef], | ||||||||||||||||||||||||||||||
| 70 | const => Optional[HashRef], | ||||||||||||||||||||||||||||||
| 71 | ], | ||||||||||||||||||||||||||||||
| 72 | ); | ||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||
| 74 | sub setup_for { | ||||||||||||||||||||||||||||||
| 75 | 7 | ▶ | my ( $me, $into, $setup ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
setup_for: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||
| 76 | 7 | ▶ | $INC{ module_notional_filename($into) } //= __FILE__; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$INC{&module_notional_filename($into)} //= __FILE__
MC/DC0%0/1
$INC{&module_notional_filename($into)} //= __FILE__
$INC{&module_notional_filename($into)}
Truth table50%1/2
A
A= $INC{&module_notional_filename($into)}
| |||||||||||||||||||||||||||||||
| 77 | 7 | my @steps = $me->steps( $into, $setup ); | |||||||||||||||||||||||||||||
| 78 | 7 | for my $step ( @steps ) { | |||||||||||||||||||||||||||||
| 79 | 31 | $me->$step( $into, $setup ); | |||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||
| 81 | 7 | return; | |||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||
| 84 | # Subclasses can wrap this to easily add and remove steps. | ||||||||||||||||||||||||||||||
| 85 | sub steps { | ||||||||||||||||||||||||||||||
| 86 | 16 | ▶ | my ( $me, $into, $setup ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
steps: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 87 | 16 | my @steps; | |||||||||||||||||||||||||||||
| 88 | 16 | push @steps, 'setup_exporter_for'; | |||||||||||||||||||||||||||||
| 89 | 16 | ▶ | push @steps, 'setup_reexports_for' if $setup->{also}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 90 | 16 | ▶ | push @steps, 'setup_enums_for' if $setup->{enum}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 91 | 16 | ▶ | push @steps, 'setup_classes_for' if $setup->{class}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 92 | 16 | ▶ | push @steps, 'setup_roles_for' if $setup->{role}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 93 | 16 | ▶ | push @steps, 'setup_ducks_for' if $setup->{duck}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 94 | 16 | ▶ | push @steps, 'setup_types_for' if $setup->{type}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 95 | 16 | ▶ | push @steps, 'setup_constants_for' if $setup->{const}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 96 | 16 | push @steps, 'setup_readonly_vars_for'; | |||||||||||||||||||||||||||||
| 97 | 16 | push @steps, 'finalize_export_variables_for'; | |||||||||||||||||||||||||||||
| 98 | 16 | return @steps; | |||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||
| 101 | sub setup_exporter_for { | ||||||||||||||||||||||||||||||
| 102 | 7 | ▶ | my ( $me, $into, $setup ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
setup_exporter_for: called CC=5 SCAR=16.2
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||
| 104 | 7 | my ( $into_ISA, undef, undef, $into_EXPORT_TAGS ) = | |||||||||||||||||||||||||||||
| 105 | $me->standard_package_variables( $into ); | ||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||
| 107 | # Set up @ISA in caller package. | ||||||||||||||||||||||||||||||
| 108 | 7 | my $base = $me->base_exporter( $into, $setup ); | |||||||||||||||||||||||||||||
| 109 | 7 | ▶ | push @$into_ISA, $base unless $into->isa( $base ); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||
| 111 | # Set up %EXPORT_TAGS in caller package. | ||||||||||||||||||||||||||||||
| 112 | 7 | ▶ | my %tags = %{ $setup->{tag} // {} }; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$setup->{"tag"} // {}
MC/DC100%1/1
$setup->{"tag"} // {}
$setup->{"tag"}
Truth table100%2/2
A
A= $setup->{"tag"}
| |||||||||||||||||||||||||||||||
| 113 | 7 | for my $tag_name ( keys %tags ) { | |||||||||||||||||||||||||||||
| 114 | 7 | my @exports = @{ assert_ArrayRef $tags{$tag_name} }; | |||||||||||||||||||||||||||||
| 115 | 7 | $tag_name =~ s/^[-:]//; | |||||||||||||||||||||||||||||
| 116 | 7 | ▶ | push @{ $into_EXPORT_TAGS->{$tag_name} //= [] }, @exports; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$into_EXPORT_TAGS->{$tag_name} //= []
MC/DC0%0/1
$into_EXPORT_TAGS->{$tag_name} //= []
$into_EXPORT_TAGS->{$tag_name}
Truth table50%1/2
A
A= $into_EXPORT_TAGS->{$tag_name}
| |||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||
| 119 | 7 | return; | |||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||
| 122 | sub setup_reexports_for { | ||||||||||||||||||||||||||||||
| 123 | 2 | ▶ | my ( $me, $into, $setup ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
setup_reexports_for: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||
| 125 | 2 | my $next = $into->can( '_exporter_validate_opts' ); | |||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||
| 127 | 2 | my $optlist = mkopt( $setup->{also} ); | |||||||||||||||||||||||||||||
| 128 | 2 | require_module( $_->[0] ) for @$optlist; | |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||
| 130 | 2 | my $method_name = "$into\::_exporter_validate_opts"; | |||||||||||||||||||||||||||||
| 131 | my $method_code = sub { | ||||||||||||||||||||||||||||||
| 132 | 2 | ▶ | my ( $class, $opts ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||
| 133 | 2 | ▶ | is_NonEmptySimpleStr( my $caller = $opts->{into} ) or return; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 134 | 2 | for my $also ( @$optlist ) { | |||||||||||||||||||||||||||||
| 135 | 4 | my ( $module, $args ) = @$also; | |||||||||||||||||||||||||||||
| 136 | 4 | ▶ | $module->import::into( $caller, @{ $args // [] } ); | ||||||||||||||||||||||||||||
|
Condition100%2/2
$args // []
MC/DC100%1/1
$args // []
$args
Truth table100%2/2
A
A= $args
| |||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||
| 138 | 2 | ▶ | goto $next if $next; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 139 | 2 | }; | |||||||||||||||||||||||||||||
| 140 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 141 | 2 | *$method_name = set_subname $method_name => $method_code; | |||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||
| 144 | sub setup_enums_for { | ||||||||||||||||||||||||||||||
| 145 | 2 | ▶ | my ( $me, $into, $setup ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
setup_enums_for: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||
| 147 | 2 | require Type::Tiny::Enum; | |||||||||||||||||||||||||||||
| 148 | 2 | my $reg = Type::Registry->for_class( $into ); | |||||||||||||||||||||||||||||
| 149 | 2 | $me->_ensure_isa_type_library( $into ); | |||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||
| 151 | 2 | ▶ | my %tags = %{ assert_HashRef $setup->{enum} // {} }; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$setup->{"enum"} // {}
MC/DC0%0/1
$setup->{"enum"} // {}
$setup->{"enum"}
Truth table50%1/2
A
A= $setup->{"enum"}
| |||||||||||||||||||||||||||||||
| 152 | 2 | for my $tag_name ( keys %tags ) { | |||||||||||||||||||||||||||||
| 153 | 2 | my $values = $tags{$tag_name}; | |||||||||||||||||||||||||||||
| 154 | 2 | $tag_name =~ s/^[-:]//; | |||||||||||||||||||||||||||||
| 155 | 2 | my $type_name = $tag_name; | |||||||||||||||||||||||||||||
| 156 | 2 | $tag_name = lc $tag_name; | |||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||
| 158 | 2 | Type::Tiny::Enum->import( { into => $into }, $type_name, $values ); | |||||||||||||||||||||||||||||
| 159 | 2 | $into->add_type( $reg->lookup( $type_name ) ); | |||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||
| 162 | 2 | return; | |||||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||
| 165 | sub setup_classes_for { | ||||||||||||||||||||||||||||||
| 166 | 1 | ▶ | my ( $me, $into, $setup ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
setup_classes_for: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 167 | 1 | require Type::Tiny::Class; | |||||||||||||||||||||||||||||
| 168 | 1 | $me->_setup_classes_or_roles_for( $into, $setup, 'class', 'Type::Tiny::Class' ); | |||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||
| 171 | sub setup_roles_for { | ||||||||||||||||||||||||||||||
| 172 | 1 | ▶ | my ( $me, $into, $setup ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
setup_roles_for: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 173 | 1 | require Type::Tiny::Role; | |||||||||||||||||||||||||||||
| 174 | 1 | $me->_setup_classes_or_roles_for( $into, $setup, 'role', 'Type::Tiny::Role' ); | |||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||||
| 177 | sub _setup_classes_or_roles_for { | ||||||||||||||||||||||||||||||
| 178 | 2 | ▶ | my ( $me, $into, $setup, $kind, $tt_class ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
_setup_classes_or_roles_for: called CC=6 SCAR=18.3
| |||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||
| 180 | 2 | my $reg = Type::Registry->for_class( $into ); | |||||||||||||||||||||||||||||
| 181 | 2 | $me->_ensure_isa_type_library( $into ); | |||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||
| 183 | 2 | my $optlist = mkopt( $setup->{$kind} ); | |||||||||||||||||||||||||||||
| 184 | 2 | for my $dfn ( @$optlist ) { | |||||||||||||||||||||||||||||
| 185 | 2 | ▶ | ( my $pkg_name = ( $dfn->[1] //= {} )->{$kind} // $dfn->[0] ); | ||||||||||||||||||||||||||||
|
Condition60%3/5
+($dfn->[1] //= {})->{$kind} // $dfn->[0]
$dfn->[1] //= {}
MC/DC0%0/2
+($dfn->[1] //= {})->{$kind} // $dfn->[0]
+($dfn->[1] //= {})->{$kind}
$dfn->[0]
MC/DC100%1/1
$dfn->[1] //= {}
$dfn->[1]
Truth table33%1/3
A // B
A= +($dfn->[1] //= {})->{$kind}B= $dfn->[0]
Truth table100%2/2
A
A= $dfn->[1]
| |||||||||||||||||||||||||||||||
| 186 | 2 | ▶ | ( my $type_name = ( $dfn->[1] //= {} )->{name} // $dfn->[0] ) =~ s/:://g; | ||||||||||||||||||||||||||||
|
Condition60%3/5
+($dfn->[1] //= {})->{"name"} // $dfn->[0]
$dfn->[1] //= {}
MC/DC0%0/2
+($dfn->[1] //= {})->{"name"} // $dfn->[0]
+($dfn->[1] //= {})->{"name"}
$dfn->[0]
MC/DC0%0/1
$dfn->[1] //= {}
$dfn->[1]
Truth table66%2/3
A // B
A= +($dfn->[1] //= {})->{"name"}B= $dfn->[0]
Truth table50%1/2
A
A= $dfn->[1]
| |||||||||||||||||||||||||||||||
| 187 | 2 | $tt_class->import( { into => $into }, @$dfn ); | |||||||||||||||||||||||||||||
| 188 | 2 | $into->add_type( $reg->lookup( $type_name ) ); | |||||||||||||||||||||||||||||
| 189 | 2 | eval { require_module( $pkg_name ) }; | |||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||
| 192 | 2 | return; | |||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||
| 195 | sub setup_ducks_for { | ||||||||||||||||||||||||||||||
| 196 | 1 | ▶ | my ( $me, $into, $setup ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
setup_ducks_for: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||
| 198 | 1 | require Type::Tiny::Duck; | |||||||||||||||||||||||||||||
| 199 | 1 | my $reg = Type::Registry->for_class( $into ); | |||||||||||||||||||||||||||||
| 200 | 1 | $me->_ensure_isa_type_library( $into ); | |||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||
| 202 | 1 | ▶ | my %types = %{ assert_HashRef $setup->{duck} // {} }; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$setup->{"duck"} // {}
MC/DC0%0/1
$setup->{"duck"} // {}
$setup->{"duck"}
Truth table50%1/2
A
A= $setup->{"duck"}
| |||||||||||||||||||||||||||||||
| 203 | 1 | for my $type_name ( keys %types ) { | |||||||||||||||||||||||||||||
| 204 | 1 | my $values = $types{$type_name}; | |||||||||||||||||||||||||||||
| 205 | 1 | Type::Tiny::Duck->import( { into => $into }, $type_name, $values ); | |||||||||||||||||||||||||||||
| 206 | 1 | $into->add_type( $reg->lookup( $type_name ) ); | |||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||
| 209 | 1 | return; | |||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||
| 212 | sub setup_types_for { | ||||||||||||||||||||||||||||||
| 213 | 2 | ▶ | my ( $me, $into, $setup ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
setup_types_for: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||
| 215 | 2 | my $reg = Type::Registry->for_class( $into ); | |||||||||||||||||||||||||||||
| 216 | 2 | $me->_ensure_isa_type_library( $into ); | |||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||
| 218 | 2 | my $optlist = mkopt( $setup->{type} ); | |||||||||||||||||||||||||||||
| 219 | 2 | my @extends = (); | |||||||||||||||||||||||||||||
| 220 | 2 | for my $dfn ( @$optlist ) { | |||||||||||||||||||||||||||||
| 221 | 2 | my ( $lib, $list ) = @$dfn; | |||||||||||||||||||||||||||||
| 222 | 2 | eval { require_module( $lib ) }; | |||||||||||||||||||||||||||||
| 223 | 2 | ▶ | if ( is_ArrayRef $list ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 224 | 1 | for my $type_name ( @$list ) { | |||||||||||||||||||||||||||||
| 225 | 1 | $into->add_type( $lib->get_type( $type_name ) ); | |||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||
| 228 | else { | ||||||||||||||||||||||||||||||
| 229 | 1 | push @extends, $lib; | |||||||||||||||||||||||||||||
| 230 | } | ||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||
| 233 | 2 | ▶ | if ( @extends ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 234 | 1 | require Type::Utils; | |||||||||||||||||||||||||||||
| 235 | 1 | my $wrapper = eval "sub { package $into; &Type::Utils::extends; }"; | |||||||||||||||||||||||||||||
| 236 | 1 | $wrapper->( @extends ); | |||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||
| 239 | 2 | return; | |||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||
| 242 | sub _ensure_isa_type_library { | ||||||||||||||||||||||||||||||
| 243 | 7 | ▶ | my ( $me, $into ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
_ensure_isa_type_library: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||
| 244 | 7 | ▶ | return if $into->isa( 'Type::Library' ); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 245 | 7 | my ( $old_isa ) = $me->standard_package_variables( $into ); | |||||||||||||||||||||||||||||
| 246 | 7 | my $new_isa = []; | |||||||||||||||||||||||||||||
| 247 | 7 | my $saw_exporter_tiny = 0; | |||||||||||||||||||||||||||||
| 248 | 7 | for my $pkg ( @$old_isa ) { | |||||||||||||||||||||||||||||
| 249 | 1 | ▶ | if ( $pkg eq 'Exporter::Tiny' ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 250 | 1 | push @$new_isa, 'Type::Library'; | |||||||||||||||||||||||||||||
| 251 | 1 | $saw_exporter_tiny++; | |||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||
| 253 | else { | ||||||||||||||||||||||||||||||
| 254 | 0 | push @$new_isa, $pkg; | |||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||
| 257 | 7 | ▶ | push @$new_isa, 'Type::Library' unless $saw_exporter_tiny; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 258 | 7 | @$old_isa = @$new_isa; | |||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||
| 261 | sub setup_constants_for { | ||||||||||||||||||||||||||||||
| 262 | 3 | ▶ | my ( $me, $into, $setup ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
setup_constants_for: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||
| 264 | 3 | my ( $into_ISA, undef, undef, $into_EXPORT_TAGS ) = | |||||||||||||||||||||||||||||
| 265 | $me->standard_package_variables( $into ); | ||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||
| 267 | 3 | ▶ | my %tags = %{ assert_HashRef $setup->{const} // {} }; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$setup->{"const"} // {}
MC/DC0%0/1
$setup->{"const"} // {}
$setup->{"const"}
Truth table50%1/2
A
A= $setup->{"const"}
| |||||||||||||||||||||||||||||||
| 268 | 3 | for my $tag_name ( keys %tags ) { | |||||||||||||||||||||||||||||
| 269 | 4 | my %exports = %{ assert_HashRef $tags{$tag_name} }; | |||||||||||||||||||||||||||||
| 270 | 4 | $tag_name =~ s/^[-:]//; | |||||||||||||||||||||||||||||
| 271 | 4 | my @constant_names = sort keys %exports; | |||||||||||||||||||||||||||||
| 272 | 4 | ▶ | push @{ $into_EXPORT_TAGS->{$tag_name} //= [] }, @constant_names; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$into_EXPORT_TAGS->{$tag_name} //= []
MC/DC0%0/1
$into_EXPORT_TAGS->{$tag_name} //= []
$into_EXPORT_TAGS->{$tag_name}
Truth table50%1/2
A
A= $into_EXPORT_TAGS->{$tag_name}
| |||||||||||||||||||||||||||||||
| 273 | 4 | ▶ | push @{ $into_EXPORT_TAGS->{'constants'} //= [] }, @constant_names; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$into_EXPORT_TAGS->{"constants"} //= []
MC/DC100%1/1
$into_EXPORT_TAGS->{"constants"} //= []
$into_EXPORT_TAGS->{"constants"}
Truth table100%2/2
A
A= $into_EXPORT_TAGS->{"constants"}
| |||||||||||||||||||||||||||||||
| 274 | 4 | $me->make_constant_subs( $into, \%exports ); | |||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||
| 277 | 3 | return; | |||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||
| 280 | sub make_constant_subs { | ||||||||||||||||||||||||||||||
| 281 | 5 | ▶ | my ( $me, $into, $constants ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
make_constant_subs: called CC=5 SCAR=16.1
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||
| 283 | 5 | for my $key ( keys %$constants ) { | |||||||||||||||||||||||||||||
| 284 | 17 | my $value = $constants->{$key}; | |||||||||||||||||||||||||||||
| 285 | 17 | my $full_name = "$into\::$key"; | |||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||
| 287 | 17 | my $coderef; | |||||||||||||||||||||||||||||
| 288 | 17 | ▶ | if ( is_Ref $value ) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 289 | 2 | $coderef = eval_closure( | |||||||||||||||||||||||||||||
| 290 | source => 'sub () { $value }', | ||||||||||||||||||||||||||||||
| 291 | environment => { '$value' => \$value }, | ||||||||||||||||||||||||||||||
| 292 | ); | ||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||
| 294 | else { | ||||||||||||||||||||||||||||||
| 295 | 15 | ▶ | $coderef = eval sprintf( | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 296 | 'sub () { %s %s }', | ||||||||||||||||||||||||||||||
| 297 | is_bool( $value ) ? '!!' : ( created_as_number( $value ) ? '0+' : '' ), | ||||||||||||||||||||||||||||||
| 298 | perlstring( $value ), | ||||||||||||||||||||||||||||||
| 299 | ); | ||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||
| 302 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 303 | 17 | *$full_name = set_subname $full_name => $coderef; | |||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||
| 307 | sub setup_readonly_vars_for { | ||||||||||||||||||||||||||||||
| 308 | 8 | ▶ | my ( $me, $into, $setup ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
setup_readonly_vars_for: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||
| 310 | 8 | my ( $into_ISA, $into_EXPORT, $into_EXPORT_OK, $into_EXPORT_TAGS ) = | |||||||||||||||||||||||||||||
| 311 | $me->standard_package_variables( $into ); | ||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||
| 313 | 8 | ▶ | my @constants = @{ $into_EXPORT_TAGS->{'constants'} // [] }; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$into_EXPORT_TAGS->{"constants"} // []
MC/DC100%1/1
$into_EXPORT_TAGS->{"constants"} // []
$into_EXPORT_TAGS->{"constants"}
Truth table100%2/2
A
A= $into_EXPORT_TAGS->{"constants"}
| |||||||||||||||||||||||||||||||
| 314 | 8 | for my $name ( @constants ) { | |||||||||||||||||||||||||||||
| 315 | 4 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 316 | 9 | my $full_name = "$into\::$name"; | |||||||||||||||||||||||||||||
| 317 | 9 | ${ $full_name } = &{ $full_name }(); | |||||||||||||||||||||||||||||
| 318 | 9 | Internals::SvREADONLY( ${ $full_name }, 1 ); | |||||||||||||||||||||||||||||
| 319 | 9 | ▶ | push @{ $into_EXPORT_TAGS->{'ro_vars'} //= [] }, '$' . $name; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$into_EXPORT_TAGS->{"ro_vars"} //= []
MC/DC100%1/1
$into_EXPORT_TAGS->{"ro_vars"} //= []
$into_EXPORT_TAGS->{"ro_vars"}
Truth table100%2/2
A
A= $into_EXPORT_TAGS->{"ro_vars"}
| |||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||
| 322 | 8 | return; | |||||||||||||||||||||||||||||
| 323 | } | ||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||
| 325 | sub finalize_export_variables_for { | ||||||||||||||||||||||||||||||
| 326 | 3 | ▶ | my ( $me, $into, $setup ) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
finalize_export_variables_for: called CC=8 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||
| 328 | 3 | my ( $into_ISA, $into_EXPORT, $into_EXPORT_OK, $into_EXPORT_TAGS ) = | |||||||||||||||||||||||||||||
| 329 | $me->standard_package_variables( $into ); | ||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||
| 331 | 3 | my %all_exports; | |||||||||||||||||||||||||||||
| 332 | 3 | ▶ | for my $list ( $into_EXPORT, $into_EXPORT_OK, values %{ $into_EXPORT_TAGS // {} } ) { | ||||||||||||||||||||||||||||
|
Condition50%1/2
$into_EXPORT_TAGS // {}
MC/DC0%0/1
$into_EXPORT_TAGS // {}
$into_EXPORT_TAGS
Truth table50%1/2
A
A= $into_EXPORT_TAGS
| |||||||||||||||||||||||||||||||
| 333 | 22 | ▶ | is_ArrayRef $list or next; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 334 | 22 | $all_exports{$_}++ for @$list; | |||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||
| 336 | 3 | @{ $into_EXPORT_OK } = sort keys %all_exports; | |||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||
| 338 | 3 | my %default_exports; | |||||||||||||||||||||||||||||
| 339 | 3 | for my $list ( $into_EXPORT, $into_EXPORT_TAGS->{default} ) { | |||||||||||||||||||||||||||||
| 340 | 6 | ▶ | is_ArrayRef $list or next; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 341 | 4 | $default_exports{$_}++ for @$list; | |||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||
| 343 | 3 | @{ $into_EXPORT } = sort keys %default_exports; | |||||||||||||||||||||||||||||
| 344 | |||||||||||||||||||||||||||||||
| 345 | 3 | return; | |||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||||
| 348 | 4 | 1; | |||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||
| 350 | __END__ | ||||||||||||||||||||||||||||||