| 1 | package PMLTQ::Base; | ||||||||||||||||||||
| 2 | 7 | our $AUTHORITY = 'cpan:MATY'; | |||||||||||||||||||
| 3 | 7 | $PMLTQ::Base::VERSION = '2.0.3'; | |||||||||||||||||||
| 4 | # ABSTRACT: Base class for PMLTQ inspired by L<Mojo::Base> and L<Mojo::Base::XS> | ||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 16 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 16 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 16 | ▶ | use utf8; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 16 | ▶ | use feature (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | # Only Perl 5.14+ requires it on demand | ||||||||||||||||||||
| 12 | 16 | ▶ | use IO::Handle (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 13 | |||||||||||||||||||||
| 14 | # Supported on Perl 5.22+ | ||||||||||||||||||||
| 15 | my $NAME | ||||||||||||||||||||
| 16 | 0 | ▶ | = eval { require Sub::Util; Sub::Util->can('set_subname') } || sub { $_[1] }; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.8
Condition33%1/3
eval {
do {
require Sub::Util;
'Sub::Util'->can('set_subname')
}
} || sub {
$_[1];
}
MC/DC0%0/2
eval {
do {
require Sub::Util;
'Sub::Util'->can('set_subname')
}
} || sub {
$_[1];
}
eval {
do {
require Sub::Util;
'Sub::Util'->can('set_subname')
}
}
sub {
$_[1];
}
Truth table33%1/3
A || B
A= eval {
do {
require Sub::Util;
'Sub::Util'->can('set_subname')
}
}B= sub {
$_[1];
}
| |||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | # Protect subclasses using AUTOLOAD | ||||||||||||||||||||
| 19 | 0 | ▶ | sub DESTROY { } | ||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 27 | ▶ | sub _monkey_patch { | ||||||||||||||||||
|
Subroutine
_monkey_patch: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 22 | 27 | my ($class, %patch) = @_; | |||||||||||||||||||
| 23 | 16 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | 16 | ▶ | no warnings 'redefine'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | 27 | *{"${class}::$_"} = $NAME->("${class}::$_", $patch{$_}) for keys %patch; | |||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 7 | require Mojo::Base::XS; | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | 7 | Mojo::Base::XS::newxs_constructor(__PACKAGE__ . '::new'); | |||||||||||||||||||
| 31 | 7 | Mojo::Base::XS::newxs_attr(__PACKAGE__ . '::attr'); | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 30 | ▶ | sub import { | ||||||||||||||||||
|
Subroutine
import: called CC=8 SCAR=20.8
| |||||||||||||||||||||
| 34 | 30 | my $class = shift; | |||||||||||||||||||
| 35 | 30 | ▶ | return unless my $flag = shift; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | # Base | ||||||||||||||||||||
| 38 | 29 | ▶ | if ($flag eq '-base') { $flag = $class } | ||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | # Strict | ||||||||||||||||||||
| 41 | 2 | elsif ($flag eq '-strict') { $flag = undef } | |||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | # Module | ||||||||||||||||||||
| 44 | ▶ | elsif ((my $file = $flag) && !$flag->can('new')) { | |||||||||||||||||||
|
Condition33%1/3
my $file = $flag and not $flag->can("new")
MC/DC0%0/2
my $file = $flag and not $flag->can("new")
my $file = $flag
not $flag->can("new")
Truth table33%1/3
A and not(B)
A= my $file = $flagB= not $flag->can("new")
| |||||||||||||||||||||
| 45 | 13 | $file =~ s!::|'!/!g; | |||||||||||||||||||
| 46 | 13 | require "$file.pm"; | |||||||||||||||||||
| 47 | } | ||||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | # ISA | ||||||||||||||||||||
| 50 | 29 | ▶ | if ($flag) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 51 | 27 | my $caller = caller; | |||||||||||||||||||
| 52 | 16 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 53 | 16 | ▶ | no warnings 'redefine'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 27 | push @{"${caller}::ISA"}, $flag; | |||||||||||||||||||
| 56 | 27 | ▶ | _monkey_patch $caller, 'has', sub { attr($caller, @_) }; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
has: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 57 | } | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | # PMLTQ modules are strict! | ||||||||||||||||||||
| 60 | 29 | $_->import for qw(strict warnings utf8); | |||||||||||||||||||
| 61 | 29 | feature->import(':5.10'); | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 7 | 1; | |||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | __END__ | ||||||||||||||||||||