| 1 | package Capture::Attribute; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 2 | $Capture::Attribute::AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||||||||
| 8 | 2 | $Capture::Attribute::VERSION = '0.003'; | |||||||||||||||||||||||||||||||||
| 9 | } | ||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Attribute::Handlers; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use Capture::Attribute::Return; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use Capture::Tiny qw//; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Carp qw//; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use Sub::Name qw//; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||
| 17 | 2 | my @importers; | |||||||||||||||||||||||||||||||||
| 18 | sub import | ||||||||||||||||||||||||||||||||||
| 19 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=4 SCAR=15.0
| |||||||||||||||||||||||||||||||||||
| 20 | 2 | my ($class, %args) = @_; | |||||||||||||||||||||||||||||||||
| 21 | my $caller = | ||||||||||||||||||||||||||||||||||
| 22 | $args{-into} | ||||||||||||||||||||||||||||||||||
| 23 | || $args{-package} | ||||||||||||||||||||||||||||||||||
| 24 | 2 | ▶ | || caller; | ||||||||||||||||||||||||||||||||
|
Condition33%2/6
$args{'-into'} || $args{'-package'} || caller
$args{"-into"} or $args{"-package"}
MC/DC0%0/3
$args{'-into'} || $args{'-package'} || caller
$args{"-into"}
$args{"-package"}
caller
Truth table25%1/4
A or B || C
A= $args{"-into"}B= $args{"-package"}C= caller
| |||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||
| 26 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 27 | 2 | push @{"$caller\::ISA"}, __PACKAGE__; | |||||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | push @importers, $caller unless $args{-keep}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||
| 31 | 2 | my ($make_replacement_coderef, $save_coderef, $saved); | |||||||||||||||||||||||||||||||||
| 32 | BEGIN | ||||||||||||||||||||||||||||||||||
| 33 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=3.3
| |||||||||||||||||||||||||||||||||||
| 34 | $make_replacement_coderef = sub | ||||||||||||||||||||||||||||||||||
| 35 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=6 SCAR=31.9
| |||||||||||||||||||||||||||||||||||
| 36 | 1 | my ($orig, $data) = @_; | |||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||
| 38 | 1 | ▶ | if ($data eq 'STDOUT') | ||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||
| 39 | { | ||||||||||||||||||||||||||||||||||
| 40 | return sub | ||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 42 | 0 | my (@args) = @_; | |||||||||||||||||||||||||||||||||
| 43 | 0 | my $wa = wantarray; | |||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | my $stdout = Capture::Tiny::capture { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 45 | $wa ? $save_coderef->(1, my @r = $orig->(@args)) : | ||||||||||||||||||||||||||||||||||
| 46 | defined $wa ? $save_coderef->(0, my $r = $orig->(@args)) : | ||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | do { $orig->(@args); $save_coderef->() } ; | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 48 | 0 | }; | |||||||||||||||||||||||||||||||||
| 49 | 0 | return $stdout; | |||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||
| 51 | 0 | } | |||||||||||||||||||||||||||||||||
| 52 | elsif ($data eq 'STDERR') | ||||||||||||||||||||||||||||||||||
| 53 | { | ||||||||||||||||||||||||||||||||||
| 54 | return sub | ||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 56 | 0 | my (@args) = @_; | |||||||||||||||||||||||||||||||||
| 57 | 0 | my $wa = wantarray; | |||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | my (undef, $stderr) = Capture::Tiny::capture { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 59 | $wa ? $save_coderef->(1, my @r = $orig->(@args)) : | ||||||||||||||||||||||||||||||||||
| 60 | defined $wa ? $save_coderef->(0, my $r = $orig->(@args)) : | ||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | do { $orig->(@args); $save_coderef->() } ; | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 62 | 0 | }; | |||||||||||||||||||||||||||||||||
| 63 | 0 | return $stderr; | |||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||
| 65 | 0 | } | |||||||||||||||||||||||||||||||||
| 66 | elsif ($data eq 'MERGED') | ||||||||||||||||||||||||||||||||||
| 67 | { | ||||||||||||||||||||||||||||||||||
| 68 | return sub | ||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 70 | 0 | my (@args) = @_; | |||||||||||||||||||||||||||||||||
| 71 | 0 | my $wa = wantarray; | |||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | my $merged = Capture::Tiny::capture_merged { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 73 | $wa ? $save_coderef->(1, my @r = $orig->(@args)) : | ||||||||||||||||||||||||||||||||||
| 74 | defined $wa ? $save_coderef->(0, my $r = $orig->(@args)) : | ||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | do { $orig->(@args); $save_coderef->() } ; | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 76 | 0 | }; | |||||||||||||||||||||||||||||||||
| 77 | 0 | return $merged; | |||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||
| 79 | 0 | } | |||||||||||||||||||||||||||||||||
| 80 | elsif ($data eq 'STDERR,STDOUT') | ||||||||||||||||||||||||||||||||||
| 81 | { | ||||||||||||||||||||||||||||||||||
| 82 | return sub | ||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||
| 84 | 0 | my (@args) = @_; | |||||||||||||||||||||||||||||||||
| 85 | 0 | my $wa = wantarray; | |||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | my @r = Capture::Tiny::capture { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||
| 87 | $wa ? $save_coderef->(1, my @r = $orig->(@args)) : | ||||||||||||||||||||||||||||||||||
| 88 | defined $wa ? $save_coderef->(0, my $r = $orig->(@args)) : | ||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | do { $orig->(@args); $save_coderef->() } ; | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 90 | 0 | }; | |||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | return wantarray ? reverse(@r[0..1]) : $r[0]; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||
| 93 | 0 | } | |||||||||||||||||||||||||||||||||
| 94 | elsif ($data eq 'STDOUT,STDERR') | ||||||||||||||||||||||||||||||||||
| 95 | { | ||||||||||||||||||||||||||||||||||
| 96 | return sub | ||||||||||||||||||||||||||||||||||
| 97 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.3
| |||||||||||||||||||||||||||||||||||
| 98 | 2 | my (@args) = @_; | |||||||||||||||||||||||||||||||||
| 99 | 2 | my $wa = wantarray; | |||||||||||||||||||||||||||||||||
| 100 | 2 | ▶ | return Capture::Tiny::capture { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=13.1
| |||||||||||||||||||||||||||||||||||
| 101 | $wa ? $save_coderef->(1, my @r = $orig->(@args)) : | ||||||||||||||||||||||||||||||||||
| 102 | defined $wa ? $save_coderef->(0, my $r = $orig->(@args)) : | ||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | do { $orig->(@args); $save_coderef->() } ; | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 104 | 2 | }; | |||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||
| 106 | 1 | } | |||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||
| 108 | 0 | return; | |||||||||||||||||||||||||||||||||
| 109 | 2 | }; | |||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||
| 111 | $save_coderef = sub | ||||||||||||||||||||||||||||||||||
| 112 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||||||||
| 113 | 2 | ▶ | if (not scalar @_) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 114 | { | ||||||||||||||||||||||||||||||||||
| 115 | 0 | $saved = Capture::Attribute::Return->new(wasarray => undef); | |||||||||||||||||||||||||||||||||
| 116 | 0 | return; | |||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||
| 119 | 2 | my $context = shift; | |||||||||||||||||||||||||||||||||
| 120 | 2 | ▶ | $saved = Capture::Attribute::Return->new( | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 121 | wasarray => $context, | ||||||||||||||||||||||||||||||||||
| 122 | value => ($context ? \@_ : $_[0]), | ||||||||||||||||||||||||||||||||||
| 123 | ); | ||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||
| 125 | 2 | } | |||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||
| 127 | INIT # runs AFTER attributes have been handled. | ||||||||||||||||||||||||||||||||||
| 128 | 2 | ▶ | { | ||||||||||||||||||||||||||||||||
|
Subroutine
INIT: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||
| 129 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 130 | 2 | foreach my $caller (@importers) | |||||||||||||||||||||||||||||||||
| 131 | { | ||||||||||||||||||||||||||||||||||
| 132 | 2 | @{"$caller\::ISA"} = grep { $_ ne __PACKAGE__ } @{"$caller\::ISA"}; | |||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||
| 134 | 2 | ▶ | no warnings 'once'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 135 | 2 | ▶ | *return = sub { $saved }; | ||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||
| 138 | 1 | ▶ | sub Capture :ATTR(CODE,RAWDATA) | ||||||||||||||||||||||||||||||||
|
Subroutine
Capture: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 139 | { | ||||||||||||||||||||||||||||||||||
| 140 | my ( | ||||||||||||||||||||||||||||||||||
| 141 | 1 | $package, | |||||||||||||||||||||||||||||||||
| 142 | $symbol, | ||||||||||||||||||||||||||||||||||
| 143 | $referent, | ||||||||||||||||||||||||||||||||||
| 144 | $attr, | ||||||||||||||||||||||||||||||||||
| 145 | $data, | ||||||||||||||||||||||||||||||||||
| 146 | $phase, | ||||||||||||||||||||||||||||||||||
| 147 | $filename, | ||||||||||||||||||||||||||||||||||
| 148 | $linenum, | ||||||||||||||||||||||||||||||||||
| 149 | ) = @_; | ||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||
| 151 | 1 | ▶ | $data = uc($data) || (my $default_data = 'STDOUT'); | ||||||||||||||||||||||||||||||||
|
Condition50%1/2
uc $data || (my $default_data = 'STDOUT')
MC/DC0%0/1
uc $data || (my $default_data = 'STDOUT')
uc $data
Truth table50%1/2
A
A= uc $data
| |||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||
| 153 | 1 | my $orig = *{$symbol}{CODE}; | |||||||||||||||||||||||||||||||||
| 154 | 1 | ▶ | my $replacement = $make_replacement_coderef->($orig, $data) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 155 | or Carp::croak "Unrecognised option string: $data"; | ||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||
| 157 | { | ||||||||||||||||||||||||||||||||||
| 158 | 2 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 159 | 2 | ▶ | no warnings 'redefine'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 160 | 1 | my $subname = sprintf '%s::%s', *{$symbol}{PACKAGE}, *{$symbol}{NAME}; | |||||||||||||||||||||||||||||||||
| 161 | 1 | *{$subname} = Sub::Name::subname($subname, $replacement); | |||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||
| 163 | 2 | ▶ | } | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||
| 165 | 2 | __PACKAGE__ | |||||||||||||||||||||||||||||||||
| 166 | __END__ | ||||||||||||||||||||||||||||||||||