| 1 | # Defines the behavior of the +shared+ keyword. | ||||||||||||||||||||||||||||
| 2 | # @api private | ||||||||||||||||||||||||||||
| 3 | package Test::Mini::Unit::Sugar::Shared; | ||||||||||||||||||||||||||||
| 4 | 13 | ▶ | use base 'Devel::Declare::Context::Simple'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 13 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 13 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 13 | ▶ | use Devel::Declare (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 47 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 11 | 47 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 12 | 47 | ▶ | my $caller = $args{into} || caller; | ||||||||||||||||||||||||||
|
Condition66%2/3
$args{'into'} || caller
MC/DC0%0/2
$args{'into'} || caller
$args{'into'}
caller
Truth table66%2/3
A || B
A= $args{'into'}B= caller
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | { | ||||||||||||||||||||||||||||
| 15 | 13 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 47 | ▶ | *{"$caller\::shared"} = sub (&) {}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | } | ||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | Devel::Declare->setup_for( | ||||||||||||||||||||||||||||
| 20 | 3 | ▶ | $caller => { shared => { const => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 3 | $class->new(%args)->parser(@_); | |||||||||||||||||||||||||||
| 22 | } } } | ||||||||||||||||||||||||||||
| 23 | 47 | ); | |||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 3 | ▶ | sub parser { | ||||||||||||||||||||||||||
|
Subroutine
parser: called CC=8 SCAR=20.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 27 | 3 | my $self = shift; | |||||||||||||||||||||||||||
| 28 | 3 | $self->init(@_); | |||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 3 | $self->skip_declarator(); | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 3 | my $name = $self->strip_name(); | |||||||||||||||||||||||||||
| 33 | 3 | ▶ | die unless $name; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | 3 | my $pkg = $self->get_curstash_name(); | |||||||||||||||||||||||||||
| 36 | 3 | my $base = 'Test::Mini::Unit::SharedBehavior'; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | # Nested packages should be namespaced under their parent, unless the | ||||||||||||||||||||||||||||
| 39 | # package name is qualified or they're in the top level. | ||||||||||||||||||||||||||||
| 40 | 3 | ▶ | $name = join('::', $pkg, $name) unless $name =~ s/^::// || $pkg eq 'main'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$name =~ s/^::// or $pkg eq "main"
MC/DC100%2/2
$name =~ s/^::// or $pkg eq "main"
$name =~ s/^:://
$pkg eq "main"
Truth table100%3/3
A or B
A= $name =~ s/^:://B= $pkg eq "main"
| |||||||||||||||||||||||||||||
| 41 | 3 | (my $file = $name) =~ s/::/\//g; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 3 | my $Sugar = 'Test::Mini::Unit::Sugar'; | |||||||||||||||||||||||||||
| 44 | 0 | ▶ | my @with = ref $self->{with} ? @{$self->{with}} : $self->{with} || (); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$self->{"with"} or ()
MC/DC50%1/2
$self->{"with"} or ()
$self->{"with"}
()
Truth table66%2/3
A or B
A= $self->{"with"}B= ()
| |||||||||||||||||||||||||||||
| 45 | 3 | ▶ | my $with = @with ? 'with => ["' . join('","', @with) . '"]' : ''; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 3 | $self->inject_if_block($_) for reverse ( | |||||||||||||||||||||||||||
| 48 | $self->scope_injector_call(), | ||||||||||||||||||||||||||||
| 49 | "package $name;", | ||||||||||||||||||||||||||||
| 50 | "use base '$base';", | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | "\$INC{'${file}.pm'} = __FILE__;", | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | "use Test::Mini::Assertions;", | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | "use ${Sugar}::Test;", | ||||||||||||||||||||||||||||
| 57 | "use ${Sugar}::Advice (name => 'setup', order => 'pre');", | ||||||||||||||||||||||||||||
| 58 | "use ${Sugar}::Advice (name => 'teardown', order => 'post');", | ||||||||||||||||||||||||||||
| 59 | 1 | (map { "use $_;" } reverse @with), | |||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 3 | ▶ | $self->shadow(sub (&) { shift->(); 1; }); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 13 | 1; | |||||||||||||||||||||||||||