| 1 | # Defines the behavior of the test advice keywords (+setup+ and +teardown+). | ||||||||||||||||||||
| 2 | # @api private | ||||||||||||||||||||
| 3 | package Test::Mini::Unit::Sugar::Advice; | ||||||||||||||||||||
| 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 B::Hooks::EndOfScope; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 13 | ▶ | use Devel::Declare (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 10 | 13 | ▶ | use Sub::Name; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 67 | ▶ | sub import { | ||||||||||||||||||
|
Subroutine
import: called CC=4 SCAR=13.9
| |||||||||||||||||||||
| 13 | 67 | my ($class, %args) = @_; | |||||||||||||||||||
| 14 | 67 | ▶ | die 'Test::Mini::Unit::Sugar::Advice requires a name argument!' unless $args{name}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | 67 | ▶ | 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
| |||||||||||||||||||||
| 17 | 67 | ▶ | my $ctx = $class->new(%args, advice => [ $caller->can($args{name}) || () ]); | ||||||||||||||||||
|
Condition66%2/3
$caller->can($args{'name'}) || ()
MC/DC0%0/2
$caller->can($args{'name'}) || ()
$caller->can($args{'name'})
()
Truth table66%2/3
A || B
A= $caller->can($args{'name'})B= ()
| |||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | { | ||||||||||||||||||||
| 20 | 13 | ▶ | no strict 'refs'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 21 | 13 | ▶ | no warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 67 | ▶ | *{"$caller\::$args{name}"} = sub (&) {}; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 67 | ▶ | on_scope_end { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 26 | 67 | ▶ | *{"$caller\::$args{name}"} = sub { $_->(@_) for @{$ctx->{advice}} }; | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | 67 | } | |||||||||||||||||||
| 29 | |||||||||||||||||||||
| 30 | Devel::Declare->setup_for( | ||||||||||||||||||||
| 31 | 25 | ▶ | $caller => { $args{name} => { const => sub { $ctx->parser(@_) } } } | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | 67 | ); | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 25 | ▶ | sub parser { | ||||||||||||||||||
|
Subroutine
parser: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||
| 36 | 25 | my $self = shift; | |||||||||||||||||||
| 37 | 25 | $self->init(@_); | |||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | 25 | $self->skip_declarator; | |||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 25 | $self->inject_if_block($_) for reverse ( | |||||||||||||||||||
| 42 | $self->scope_injector_call(), | ||||||||||||||||||||
| 43 | 'my $self = shift;', | ||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 25 | ▶ | if ($self->{order} eq 'pre') { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 47 | 15 | ▶ | $self->shadow(sub (&) { push @{$self->{advice}}, @_ }); | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | elsif ($self->{order} eq 'post') { | ||||||||||||||||||||
| 50 | 10 | ▶ | $self->shadow(sub (&) { unshift @{$self->{advice}}, @_ }); | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 51 | } | ||||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 13 | 1; | |||||||||||||||||||