| 1 | # -*- mode: perl; coding: utf-8 -*- | ||||||||||||||||||||
| 2 | package YATT::Util::Finalizer; | ||||||||||||||||||||
| 3 | 12 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | 12 | ▶ | use warnings qw(FATAL all NONFATAL misc); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | |||||||||||||||||||||
| 6 | 12 | ▶ | use base qw(Exporter); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 12 | ▶ | BEGIN { | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 12 | our @EXPORT = qw(with_select capture finally); | |||||||||||||||||||
| 9 | 12 | our @EXPORT_OK = @EXPORT; | |||||||||||||||||||
| 10 | } | ||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | 162 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 13 | 162 | my ($pack, $code) = splice @_, 0, 2; | |||||||||||||||||||
| 14 | 162 | bless [$code, @_], $pack; | |||||||||||||||||||
| 15 | } | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | 162 | ▶ | sub finally (&@) { | ||||||||||||||||||
|
Subroutine
finally: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 18 | 162 | __PACKAGE__->new(@_); | |||||||||||||||||||
| 19 | } | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 162 | ▶ | sub DESTROY { | ||||||||||||||||||
|
Subroutine
DESTROY: called CC=4 SCAR=14.1
| |||||||||||||||||||||
| 22 | 162 | my $self = shift; | |||||||||||||||||||
| 23 | 162 | ▶ | if ($@) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 24 | # XXX: This can be hard to catch. | ||||||||||||||||||||
| 25 | 32 | ▶ | syswrite STDOUT, "\n\n[$@]" if $ENV{DEBUG_ERROR}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 26 | } | ||||||||||||||||||||
| 27 | 162 | ▶ | my $code = $self->[0] or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 28 | 162 | $code->(@$self[1 .. $#$self]); | |||||||||||||||||||
| 29 | } | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | 0 | ▶ | sub cancel { | ||||||||||||||||||
|
Subroutine
cancel: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 32 | 0 | undef shift->[0]; | |||||||||||||||||||
| 33 | } | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 162 | ▶ | sub with_select { | ||||||||||||||||||
|
Subroutine
with_select: called CC=5 SCAR=16.8
Pod
undocumented
| |||||||||||||||||||||
| 36 | # newfh, body, [strref] | ||||||||||||||||||||
| 37 | 162 | my $strref; | |||||||||||||||||||
| 38 | 162 | ▶ | unless (defined $_[0]) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 39 | 162 | ▶ | $strref = $_[2] || do {my $str = ""; \$str}; | ||||||||||||||||||
|
Condition33%1/3
$_[2] || do {
my $str = '';
\$str
}
MC/DC0%0/2
$_[2] || do {
my $str = '';
\$str
}
$_[2]
do {
my $str = '';
\$str
}
Truth table33%1/3
A || B
A= $_[2]B= do {
my $str = '';
\$str
}
| |||||||||||||||||||||
| 40 | 162 | ▶ | open $_[0], '>', $strref or die "Can't open strref: $!"; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 41 | } | ||||||||||||||||||||
| 42 | 162 | ▶ | my $finalizer = finally { | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 43 | 162 | select($_[0]); | |||||||||||||||||||
| 44 | 162 | } select; | |||||||||||||||||||
| 45 | 162 | select($_[0]); | |||||||||||||||||||
| 46 | 162 | $_[1]->($finalizer); | |||||||||||||||||||
| 47 | 130 | ▶ | defined $strref && $$strref; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 162 | ▶ | sub capture (&@) { | ||||||||||||||||||
|
Subroutine
capture: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 51 | 162 | with_select my ($fh), $_[0]; | |||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 12 | 1; | |||||||||||||||||||