| 1 | package TUI::toolkit; | ||||||||||||||||||||||||||||
| 2 | # ABSTRACT: Unified OO facade for the TUI::Vision framework | ||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 672 | ▶ | use 5.010; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 672 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 441 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 136 | our $VERSION = '0.08'; | |||||||||||||||||||||||||||
| 9 | 136 | our $AUTHORITY = 'cpan:BRICKPOOL'; | |||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 331 | ▶ | use autodie::Scope::Guard (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 218 | ▶ | use Carp (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 209 | ▶ | use Devel::StrictMode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 202 | ▶ | use Import::Into; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 188 | ▶ | use Module::Loaded (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 186 | ▶ | use PerlX::Assert::PP; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 182 | ▶ | use Symbol (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 179 | ▶ | use Importer (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 136 | our @EXPORT = qw( | |||||||||||||||||||||||||||
| 21 | true | ||||||||||||||||||||||||||||
| 22 | false | ||||||||||||||||||||||||||||
| 23 | assert | ||||||||||||||||||||||||||||
| 24 | has | ||||||||||||||||||||||||||||
| 25 | extends | ||||||||||||||||||||||||||||
| 26 | signature | ||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 136 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||
| 30 | is_Moo | ||||||||||||||||||||||||||||
| 31 | is_Moos | ||||||||||||||||||||||||||||
| 32 | is_Moose | ||||||||||||||||||||||||||||
| 33 | is_UNIVERSAL | ||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 136 | our %EXPORT_TAGS = ( | |||||||||||||||||||||||||||
| 37 | all => [ | ||||||||||||||||||||||||||||
| 38 | @EXPORT, | ||||||||||||||||||||||||||||
| 39 | @EXPORT_OK | ||||||||||||||||||||||||||||
| 40 | ], | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | backend => [ | ||||||||||||||||||||||||||||
| 43 | @EXPORT_OK | ||||||||||||||||||||||||||||
| 44 | ], | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | boolean => [qw( | ||||||||||||||||||||||||||||
| 47 | true | ||||||||||||||||||||||||||||
| 48 | false | ||||||||||||||||||||||||||||
| 49 | )], | ||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | oo => [qw( | ||||||||||||||||||||||||||||
| 52 | has | ||||||||||||||||||||||||||||
| 53 | extends | ||||||||||||||||||||||||||||
| 54 | )], | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | utils => [qw( | ||||||||||||||||||||||||||||
| 57 | assert | ||||||||||||||||||||||||||||
| 58 | signature | ||||||||||||||||||||||||||||
| 59 | )], | ||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 176 | ▶ | BEGIN { $] >= 5.010 ? require mro : require MRO::Compat } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | 176 | ▶ | BEGIN { require Devel::GlobalDestruction unless $] >= 5.014 } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.6
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | 176 | ▶ | BEGIN { *PERL_ONLY = $ENV{PERL_ONLY} ? sub() { !!1 } : sub() { !!0 } } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.6
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Subroutine
BEGIN: called CC=1 SCAR=0.4
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 65 | 2209 | ▶ | BEGIN { sub XS_ASSERT () { eval q[ require PerlX::Assert ]; !$@ } } | ||||||||||||||||||||||||||
|
Subroutine
XS_ASSERT: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 66 | 170 | ▶ | BEGIN { sub XS_PARAMS () { eval q[ use Type::Params 2 ]; !$@ } } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
XS_PARAMS: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 67 | 1955 | ▶ | BEGIN { sub SUB_UTIL () { eval q[ require Sub::Util ]; !$@ } } | ||||||||||||||||||||||||||
|
Subroutine
SUB_UTIL: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 136 | our $name; | |||||||||||||||||||||||||||
| 70 | 170 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 71 | 176 | $name = 'UNIVERSAL::Object'; # default if no other toolkit is found | |||||||||||||||||||||||||||
| 72 | 176 | foreach my $toolkit ( qw( Moose Moo Moos ) ) { | |||||||||||||||||||||||||||
| 73 | 445 | ▶ | if ( Module::Loaded::is_loaded $toolkit ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 74 | 42 | $name = $toolkit; | |||||||||||||||||||||||||||
| 75 | 40 | last; | |||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 1640 | ▶ | sub is_Moo (){ $name eq 'Moo' } | ||||||||||||||||||||||||||
|
Subroutine
is_Moo: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 80 | 1521 | ▶ | sub is_Moos (){ $name eq 'Moos' } | ||||||||||||||||||||||||||
|
Subroutine
is_Moos: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 81 | 1526 | ▶ | sub is_Moose (){ $name eq 'Moose' } | ||||||||||||||||||||||||||
|
Subroutine
is_Moose: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 82 | 1522 | ▶ | sub is_UNIVERSAL (){ $name eq 'UNIVERSAL::Object' } | ||||||||||||||||||||||||||
|
Subroutine
is_UNIVERSAL: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 136 | our %ADDED = (); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 136 | my %DEFAULT = ( | |||||||||||||||||||||||||||
| 88 | Moose => [qw( extends with has before after around override super augment | ||||||||||||||||||||||||||||
| 89 | inner blessed confess )], | ||||||||||||||||||||||||||||
| 90 | Moo => [qw( extends with has before after around )], | ||||||||||||||||||||||||||||
| 91 | Moos => [qw( extends with has blessed confess )], | ||||||||||||||||||||||||||||
| 92 | 'UNIVERSAL::Object' => [qw( extends has blessed confess )], | ||||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 2341 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=18 SCAR=29.4
| |||||||||||||||||||||||||||||
| 96 | 2351 | my ( $class, @imports ) = @_; | |||||||||||||||||||||||||||
| 97 | 2351 | my $caller = caller(); | |||||||||||||||||||||||||||
| 98 | 2351 | ▶ | return if $^H{ __PACKAGE__ . "/$caller" }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | # Resolve semantic imports | ||||||||||||||||||||||||||||
| 101 | 2347 | my $exports = Importer->get( $class, @imports ); | |||||||||||||||||||||||||||
| 102 | 2345 | my %want = map { $_ => 1 } keys %$exports; | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | # OO backend routing | ||||||||||||||||||||||||||||
| 105 | 2345 | ▶ | if ( my @syms = grep { $want{$_} } @{ $DEFAULT{$name} } ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | # Note: strict and warnings will also be enabled for caller | ||||||||||||||||||||||||||||
| 108 | SWITCH: { | ||||||||||||||||||||||||||||
| 109 | 1521 | ▶ | is_Moose and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 25 | require Moose; | |||||||||||||||||||||||||||
| 111 | 25 | Moose->import::into( $caller, @syms ); | |||||||||||||||||||||||||||
| 112 | 25 | last; | |||||||||||||||||||||||||||
| 113 | }; | ||||||||||||||||||||||||||||
| 114 | 1515 | ▶ | is_Moo and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 115 | 25 | require Moo; | |||||||||||||||||||||||||||
| 116 | 23 | Moo->import::into( $caller, @syms ); | |||||||||||||||||||||||||||
| 117 | 23 | last; | |||||||||||||||||||||||||||
| 118 | }; | ||||||||||||||||||||||||||||
| 119 | 1511 | ▶ | is_Moos and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 20 | require Moos; | |||||||||||||||||||||||||||
| 121 | 20 | _my_moos_export( $caller, @syms ); | |||||||||||||||||||||||||||
| 122 | 20 | ▶ | _around_hook( $caller, has => \&_my_moos_has ) if $want{has}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 123 | 20 | ▶ | _add_demolish( 'Moos::Object' ) unless $ADDED{DEMOLISH}++; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 124 | 20 | last; | |||||||||||||||||||||||||||
| 125 | }; | ||||||||||||||||||||||||||||
| 126 | 1510 | ▶ | is_UNIVERSAL and do { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 127 | 1509 | require TUI::toolkit::UO::Antlers; | |||||||||||||||||||||||||||
| 128 | 1509 | TUI::toolkit::UO::Antlers->import::into( $caller, @syms ); | |||||||||||||||||||||||||||
| 129 | 1509 | last; | |||||||||||||||||||||||||||
| 130 | }; | ||||||||||||||||||||||||||||
| 131 | DEFAULT: { | ||||||||||||||||||||||||||||
| 132 | 18 | warn "No backend for TUI::toolkit\n"; | |||||||||||||||||||||||||||
| 133 | 18 | last; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | } #/ SWITCH: | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | } #/ if ( my @syms = grep {...}) | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | # boolean backend routing | ||||||||||||||||||||||||||||
| 140 | 2334 | ▶ | if ( $want{true} || $want{false} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$want{"true"} or $want{"false"}
MC/DC50%1/2
$want{"true"} or $want{"false"}
$want{"true"}
$want{"false"}
Truth table66%2/3
A or B
A= $want{"true"}B= $want{"false"}
| |||||||||||||||||||||||||||||
| 141 | 1740 | require TUI::toolkit::boolean; | |||||||||||||||||||||||||||
| 142 | TUI::toolkit::boolean->import::into( $caller, | ||||||||||||||||||||||||||||
| 143 | 1740 | grep { $want{$_} } qw( true false ) | |||||||||||||||||||||||||||
| 144 | ); | ||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | # assert routed to backend | ||||||||||||||||||||||||||||
| 148 | 2334 | ▶ | if ( $want{assert} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 2189 | ▶ | if ( XS_ASSERT and not PERL_ONLY ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
&XS_ASSERT() and
MC/DC0%0/1
&XS_ASSERT() and
&XS_ASSERT()
Truth table50%1/2
A
A= &XS_ASSERT()
| |||||||||||||||||||||||||||||
| 150 | # suppress void warnings for XS backend | ||||||||||||||||||||||||||||
| 151 | 2189 | warnings->unimport( 'void' ); | |||||||||||||||||||||||||||
| 152 | 2189 | PerlX::Assert->import::into( $caller, 'assert' ); | |||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||
| 154 | else { | ||||||||||||||||||||||||||||
| 155 | 16 | PerlX::Assert::PP->import::into( $caller ); | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | # signature routed to backend | ||||||||||||||||||||||||||||
| 160 | 2319 | ▶ | if ( $want{signature} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 2318 | ▶ | if ( XS_PARAMS and not PERL_ONLY ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
&XS_PARAMS() and
MC/DC0%0/1
&XS_PARAMS() and
&XS_PARAMS()
Truth table50%1/2
A
A= &XS_PARAMS()
| |||||||||||||||||||||||||||||
| 162 | 2318 | Type::Params->import::into( $caller, 'signature' ); | |||||||||||||||||||||||||||
| 163 | } | ||||||||||||||||||||||||||||
| 164 | else { | ||||||||||||||||||||||||||||
| 165 | 0 | TUI::toolkit::Params->import::into( $caller, 'signature' ); | |||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | # Add a dump method to the class if it doesn't already have one | ||||||||||||||||||||||||||||
| 170 | 2336 | ▶ | $^H{ __PACKAGE__ . "/$caller" } = autodie::Scope::Guard->new(sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 171 | 2318 | ▶ | _add_dump( $caller ) unless $caller->can( 'dump' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 172 | 2318 | }); | |||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | # exports living in this module | ||||||||||||||||||||||||||||
| 175 | Importer->import_into( $class, $caller, $_ ) | ||||||||||||||||||||||||||||
| 176 | 2318 | for grep { $want{$_} } @{ $EXPORT_TAGS{backend} }; | |||||||||||||||||||||||||||
| 177 | } #/ sub import | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 20 | ▶ | sub unimport { | ||||||||||||||||||||||||||
|
Subroutine
unimport: called CC=9 SCAR=24.8
| |||||||||||||||||||||||||||||
| 180 | 4 | my $caller = caller(); | |||||||||||||||||||||||||||
| 181 | 4 | ▶ | return unless $^H{ __PACKAGE__ . "/$caller" }; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 3 | ▶ | if ( XS_PARAMS and not PERL_ONLY ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
&XS_PARAMS() and
MC/DC0%0/1
&XS_PARAMS() and
&XS_PARAMS()
Truth table50%1/2
A
A= &XS_PARAMS()
| |||||||||||||||||||||||||||||
| 184 | 3 | Type::Params->unimport::out_of( $caller ); | |||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||
| 186 | else { | ||||||||||||||||||||||||||||
| 187 | 0 | TUI::toolkit::Params->unimport::out_of( $caller ); | |||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||
| 189 | 3 | ▶ | if ( XS_ASSERT and not PERL_ONLY ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
&XS_ASSERT() and
MC/DC0%0/1
&XS_ASSERT() and
&XS_ASSERT()
Truth table50%1/2
A
A= &XS_ASSERT()
| |||||||||||||||||||||||||||||
| 190 | 3 | PerlX::Assert->unimport::out_of( $caller ); | |||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||
| 192 | else { | ||||||||||||||||||||||||||||
| 193 | 0 | PerlX::Assert::PP->unimport::out_of( $caller ); | |||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | 3 | TUI::toolkit::boolean->unimport::out_of( $caller ); | |||||||||||||||||||||||||||
| 196 | 3 | ▶ | if ( is_Moose ) { | ||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||
| 197 | 1 | Moose->unimport::out_of( $caller ); | |||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||
| 199 | elsif ( is_Moo ) { | ||||||||||||||||||||||||||||
| 200 | 0 | Moo->unimport::out_of( $caller ); | |||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||
| 202 | elsif ( is_Moos ) { | ||||||||||||||||||||||||||||
| 203 | 0 | Moos->unimport::out_of( $caller ); | |||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||
| 206 | 3 | $^H{ __PACKAGE__ . "/$caller" } = 0; | |||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | # Split fully qualified name into package and symbol | ||||||||||||||||||||||||||||
| 210 | 1940 | ▶ | sub _split_fqn { # ($pkg, $sym) = _split_fqn($fqn) | ||||||||||||||||||||||||||
|
Subroutine
_split_fqn: called CC=5 SCAR=18.9
| |||||||||||||||||||||||||||||
| 211 | 1924 | my ( $fqn ) = @_; | |||||||||||||||||||||||||||
| 212 | 1924 | ▶ | assert ( defined $fqn && !ref $fqn ); | ||||||||||||||||||||||||||
|
Condition33%1/3
defined $fqn && !ref($fqn)
MC/DC0%0/2
defined $fqn && !ref($fqn)
defined $fqn
!ref($fqn)
Truth table33%1/3
A && not(B)
A= defined $fqnB= !ref($fqn)
| |||||||||||||||||||||||||||||
| 213 | 1924 | ▶ | my ( $pkg, $sym ) = $fqn =~ m/^(.*)::([^:]+)\z/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 214 | ? ( $1, $2 ) | ||||||||||||||||||||||||||||
| 215 | : ( 'main', $fqn ); | ||||||||||||||||||||||||||||
| 216 | 1924 | ▶ | $pkg = 'main' if !defined( $pkg ) || $pkg eq ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $pkg or $pkg eq ""
MC/DC0%0/2
not defined $pkg or $pkg eq ""
not defined $pkg
$pkg eq ""
Truth table33%1/3
not(A) or B
A= not defined $pkgB= $pkg eq ""
| |||||||||||||||||||||||||||||
| 217 | 1924 | return ( $pkg, $sym ); | |||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | # Get the symbol table hash for a package, or undef if it does not exist | ||||||||||||||||||||||||||||
| 221 | 1940 | ▶ | sub _get_package_stash { # \%stash|undef ($pkg) | ||||||||||||||||||||||||||
|
Subroutine
_get_package_stash: called CC=8 SCAR=21.3
| |||||||||||||||||||||||||||||
| 222 | 1924 | my ( $pkg ) = @_; | |||||||||||||||||||||||||||
| 223 | 1924 | ▶ | assert ( defined $pkg && !ref $pkg ); | ||||||||||||||||||||||||||
|
Condition33%1/3
defined $pkg && !ref($pkg)
MC/DC0%0/2
defined $pkg && !ref($pkg)
defined $pkg
!ref($pkg)
Truth table33%1/3
A && not(B)
A= defined $pkgB= !ref($pkg)
| |||||||||||||||||||||||||||||
| 224 | |||||||||||||||||||||||||||||
| 225 | 1924 | ▶ | return \%:: if $pkg eq '' || $pkg eq 'main'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$pkg eq "" or $pkg eq "main"
MC/DC50%1/2
$pkg eq "" or $pkg eq "main"
$pkg eq ""
$pkg eq "main"
Truth table66%2/3
A or B
A= $pkg eq ""B= $pkg eq "main"
| |||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||
| 227 | 1919 | $pkg =~ s/::\z//; | |||||||||||||||||||||||||||
| 228 | 1919 | my @parts = split /::/, $pkg; | |||||||||||||||||||||||||||
| 229 | 1919 | my $stash = \%::; # main:: | |||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 174 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 232 | 1919 | for my $p (@parts) { | |||||||||||||||||||||||||||
| 233 | 5817 | ▶ | return undef if $p eq ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | 5817 | my $key = "${p}::"; | |||||||||||||||||||||||||||
| 235 | 5817 | ▶ | return undef if !exists $stash->{$key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 236 | 5817 | my $glob = $stash->{$key}; | |||||||||||||||||||||||||||
| 237 | 5817 | ▶ | my $next = *{$glob}{HASH} or return undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 238 | 5817 | $stash = $next; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | 1919 | return $stash; | |||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | # Adds a new method to an existing class | ||||||||||||||||||||||||||||
| 244 | 1925 | ▶ | sub _create_method { # void ($class, $name, \&code) | ||||||||||||||||||||||||||
|
Subroutine
_create_method: called CC=6 SCAR=20.3
| |||||||||||||||||||||||||||||
| 245 | 1924 | my ( $class, $name, $code ) = @_; | |||||||||||||||||||||||||||
| 246 | 1924 | ▶ | assert ( defined $class and !ref $class ); | ||||||||||||||||||||||||||
|
Condition33%1/3
defined $class && !ref($class)
MC/DC0%0/2
defined $class && !ref($class)
defined $class
!ref($class)
Truth table33%1/3
A && not(B)
A= defined $classB= !ref($class)
| |||||||||||||||||||||||||||||
| 247 | 1924 | ▶ | assert ( defined $name and !ref $name ); | ||||||||||||||||||||||||||
|
Condition33%1/3
defined $name && !ref($name)
MC/DC0%0/2
defined $name && !ref($name)
defined $name
!ref($name)
Truth table33%1/3
A && not(B)
A= defined $nameB= !ref($name)
| |||||||||||||||||||||||||||||
| 248 | 1924 | ▶ | assert ( defined $code and ref $code eq 'CODE' ); | ||||||||||||||||||||||||||
|
Condition33%1/3
defined $code && ref $code eq 'CODE'
MC/DC0%0/2
defined $code && ref $code eq 'CODE'
defined $code
ref $code eq 'CODE'
Truth table33%1/3
A && B
A= defined $codeB= ref $code eq 'CODE'
| |||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||
| 250 | # Build fully-qualified name (keeps $name if already qualified) | ||||||||||||||||||||||||||||
| 251 | 1924 | my $fqn = Symbol::qualify( $name, $class ); | |||||||||||||||||||||||||||
| 252 | 1924 | my ( $pkg, $sym ) = _split_fqn( $fqn ); | |||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 1924 | my $stash = _get_package_stash( $pkg ); | |||||||||||||||||||||||||||
| 255 | 1924 | ▶ | unless ( defined $stash ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 256 | 0 | warn "Cannot add method $fqn to non-existing package $pkg\n"; | |||||||||||||||||||||||||||
| 257 | 0 | return; | |||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 1924 | ▶ | $code = Sub::Util::set_subname( $fqn, $code ) if SUB_UTIL; # nicer traces | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 261 | 1924 | my $glob = Symbol::qualify_to_ref( $sym, $pkg ); | |||||||||||||||||||||||||||
| 262 | 1924 | *{$glob} = $code; # warns if redefining an existing method | |||||||||||||||||||||||||||
| 263 | 1924 | return; | |||||||||||||||||||||||||||
| 264 | } #/ sub _create_method | ||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | # An around method modifier without checking of an existing method | ||||||||||||||||||||||||||||
| 267 | 0 | ▶ | sub _around_hook { # void ($class, $name, \&code) | ||||||||||||||||||||||||||
|
Subroutine
_around_hook: not called CC=7 SCAR=38.2
| |||||||||||||||||||||||||||||
| 268 | 0 | my ( $class, $name, $code ) = @_; | |||||||||||||||||||||||||||
| 269 | 0 | ▶ | assert ( defined $class and !ref $class ); | ||||||||||||||||||||||||||
|
Condition0%0/3
defined $class && !ref($class)
MC/DC0%0/2
defined $class && !ref($class)
defined $class
!ref($class)
Truth table0%0/3
A && not(B)
A= defined $classB= !ref($class)
| |||||||||||||||||||||||||||||
| 270 | 0 | ▶ | assert ( defined $name and !ref $name ); | ||||||||||||||||||||||||||
|
Condition0%0/3
defined $name && !ref($name)
MC/DC0%0/2
defined $name && !ref($name)
defined $name
!ref($name)
Truth table0%0/3
A && not(B)
A= defined $nameB= !ref($name)
| |||||||||||||||||||||||||||||
| 271 | 0 | ▶ | assert ( defined $code and ref $code eq 'CODE' ); | ||||||||||||||||||||||||||
|
Condition0%0/3
defined $code && ref $code eq 'CODE'
MC/DC0%0/2
defined $code && ref $code eq 'CODE'
defined $code
ref $code eq 'CODE'
Truth table0%0/3
A && B
A= defined $codeB= ref $code eq 'CODE'
| |||||||||||||||||||||||||||||
| 272 | |||||||||||||||||||||||||||||
| 273 | 0 | my $fqn = Symbol::qualify( $name, $class ); # builds full name | |||||||||||||||||||||||||||
| 274 | 0 | my ( $pkg, $sym ) = _split_fqn( $fqn ); | |||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 0 | my $stash = _get_package_stash( $pkg ); | |||||||||||||||||||||||||||
| 277 | 0 | ▶ | unless ( defined $stash ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 278 | 0 | warn "Cannot hook method $fqn from non-existing package $pkg\n"; | |||||||||||||||||||||||||||
| 279 | 0 | return; | |||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | # glob ref for installation | ||||||||||||||||||||||||||||
| 283 | 0 | my $glob = Symbol::qualify_to_ref( $sym, $pkg ); | |||||||||||||||||||||||||||
| 284 | 0 | my $orig = *{$glob}{CODE}; | |||||||||||||||||||||||||||
| 285 | 0 | ▶ | unless ( $orig ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 286 | 0 | warn "Cannot wrap non-existing method $fqn\n"; | |||||||||||||||||||||||||||
| 287 | 0 | return; | |||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||
| 290 | 0 | ▶ | my $wrapper = sub { $code->( $orig, @_ ) }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 291 | 0 | ▶ | $wrapper = Sub::Util::set_subname( $fqn, $wrapper ) if SUB_UTIL; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | 174 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 294 | 0 | *{$glob} = $wrapper; | |||||||||||||||||||||||||||
| 295 | 0 | return; | |||||||||||||||||||||||||||
| 296 | } #/ sub _around_hook | ||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||
| 298 | # We are I<patching> the Moos C<has> arguments to support C<< is => 'bare' >> | ||||||||||||||||||||||||||||
| 299 | # and C<< default => scalar|ref >> | ||||||||||||||||||||||||||||
| 300 | 0 | ▶ | sub _my_moos_has { # $return (\&orig, $self, @_) | ||||||||||||||||||||||||||
|
Subroutine
_my_moos_has: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||
| 301 | 0 | my ( $orig, $self, %args ) = @_; | |||||||||||||||||||||||||||
| 302 | 0 | ▶ | if ( exists $args{is} && $args{is} eq 'bare' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $args{"is"} and $args{"is"} eq "bare"
MC/DC0%0/2
exists $args{"is"} and $args{"is"} eq "bare"
exists $args{"is"}
$args{"is"} eq "bare"
Truth table0%0/3
A and B
A= exists $args{"is"}B= $args{"is"} eq "bare"
| |||||||||||||||||||||||||||||
| 303 | 0 | $args{is} = 'rw'; | |||||||||||||||||||||||||||
| 304 | 0 | $args{_skip_setup} = 1; | |||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||
| 306 | 0 | ▶ | if ( exists $args{default} && ref $args{default} ne 'CODE' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
exists $args{"default"} and ref $args{"default"} ne "CODE"
MC/DC0%0/2
exists $args{"default"} and ref $args{"default"} ne "CODE"
exists $args{"default"}
ref $args{"default"} ne "CODE"
Truth table0%0/3
A and B
A= exists $args{"default"}B= ref $args{"default"} ne "CODE"
| |||||||||||||||||||||||||||||
| 307 | 0 | my $default = $args{default}; | |||||||||||||||||||||||||||
| 308 | 0 | ▶ | $args{default} = sub { $default }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||
| 310 | 0 | return $self->$orig( %args ); | |||||||||||||||||||||||||||
| 311 | } #/ sub _my_moos_has | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | # Import only what is requested and not the Moos default | ||||||||||||||||||||||||||||
| 314 | 0 | ▶ | sub _my_moos_export { # void ($caller, @names) | ||||||||||||||||||||||||||
|
Subroutine
_my_moos_export: not called CC=3 SCAR=20.0
| |||||||||||||||||||||||||||||
| 315 | 0 | my ( $caller, @names ) = @_; | |||||||||||||||||||||||||||
| 316 | { | ||||||||||||||||||||||||||||
| 317 | 0 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.2
| |||||||||||||||||||||||||||||
| 318 | 0 | ▶ | local *Moos::_export = sub { }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 319 | 0 | Moos->import::into( $caller ); | |||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||
| 321 | 0 | my $meta = Moos::Meta::Class->initialize( $caller ); | |||||||||||||||||||||||||||
| 322 | 0 | for my $name ( @names ) { | |||||||||||||||||||||||||||
| 323 | 0 | ▶ | my $code = Moos->can( $name ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 324 | or Carp::croak "Moos has no keyword '$name'"; | ||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||
| 326 | 0 | Moos::_export( $caller, $name => $code, $meta ); | |||||||||||||||||||||||||||
| 327 | } | ||||||||||||||||||||||||||||
| 328 | 0 | return; | |||||||||||||||||||||||||||
| 329 | } | ||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | # Provide an equivalent dump method using L<Data::Dumper>, unless one already | ||||||||||||||||||||||||||||
| 332 | # exists | ||||||||||||||||||||||||||||
| 333 | 1923 | ▶ | sub _add_dump { # void ($target) | ||||||||||||||||||||||||||
|
Subroutine
_add_dump: called CC=2 SCAR=9.8
| |||||||||||||||||||||||||||||
| 334 | 1923 | my ( $proto ) = @_; | |||||||||||||||||||||||||||
| 335 | 1923 | assert ( $proto ); | |||||||||||||||||||||||||||
| 336 | 1923 | ▶ | my $target = ref $proto || $proto; | ||||||||||||||||||||||||||
|
Condition33%1/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 337 | _create_method( $target, | ||||||||||||||||||||||||||||
| 338 | 0 | ▶ | dump => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.0
| |||||||||||||||||||||||||||||
| 339 | 173 | ▶ | no warnings 'once'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 340 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 341 | 0 | require Data::Dumper; | |||||||||||||||||||||||||||
| 342 | 0 | local $Data::Dumper::Sortkeys = 1; | |||||||||||||||||||||||||||
| 343 | 0 | ▶ | local $Data::Dumper::Maxdepth = shift if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 344 | 0 | my $str = Data::Dumper::Dumper $self; | |||||||||||||||||||||||||||
| 345 | 0 | $str =~ s/(^|\s)\$VAR\d+\b/$1'$self'/g; | |||||||||||||||||||||||||||
| 346 | 0 | return $str; | |||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||
| 348 | 1923 | ); | |||||||||||||||||||||||||||
| 349 | 1923 | return; | |||||||||||||||||||||||||||
| 350 | } | ||||||||||||||||||||||||||||
| 351 | |||||||||||||||||||||||||||||
| 352 | # Provide DEMOLISH if it is not available | ||||||||||||||||||||||||||||
| 353 | 0 | ▶ | sub _add_demolish { # void ($target) | ||||||||||||||||||||||||||
|
Subroutine
_add_demolish: not called CC=3 SCAR=22.7
| |||||||||||||||||||||||||||||
| 354 | 0 | my ( $proto ) = @_; | |||||||||||||||||||||||||||
| 355 | 0 | assert ( $proto ); | |||||||||||||||||||||||||||
| 356 | 0 | ▶ | my $target = ref $proto || $proto; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $proto || $proto
MC/DC0%0/2
ref $proto || $proto
ref $proto
$proto
Truth table0%0/3
A || B
A= ref $protoB= $proto
| |||||||||||||||||||||||||||||
| 357 | 0 | ▶ | return if $target->can( 'DESTROY' ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 358 | _create_method( $target, | ||||||||||||||||||||||||||||
| 359 | 0 | ▶ | DESTROY => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=30.1
| |||||||||||||||||||||||||||||
| 360 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 361 | 0 | ▶ | my $class = ref $self || $self; | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $self || $self
MC/DC0%0/2
ref $self || $self
ref $self
$self
Truth table0%0/3
A || B
A= ref $selfB= $self
| |||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | 0 | ▶ | my $in_global_destruction = defined ${^GLOBAL_PHASE} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 364 | ? ${^GLOBAL_PHASE} eq 'DESTRUCT' | ||||||||||||||||||||||||||||
| 365 | : Devel::GlobalDestruction::in_global_destruction(); | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | # Call all DEMOLISH methods starting with the derived classes. | ||||||||||||||||||||||||||||
| 368 | 0 | foreach ( @{ mro::get_linear_isa( $class ) } ) { | |||||||||||||||||||||||||||
| 369 | 170 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 370 | 0 | my $demolish = *{$_.'::DEMOLISH'}{CODE}; | |||||||||||||||||||||||||||
| 371 | 0 | ▶ | next unless $demolish; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 372 | 0 | $self->$demolish( $in_global_destruction ) | |||||||||||||||||||||||||||
| 373 | } | ||||||||||||||||||||||||||||
| 374 | 0 | return; | |||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||
| 376 | 0 | ); | |||||||||||||||||||||||||||
| 377 | 0 | return; | |||||||||||||||||||||||||||
| 378 | } | ||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||
| 380 | 136 | 1 | |||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||
| 382 | __END__ | ||||||||||||||||||||||||||||