web/cgi-bin/yatt.lib/YATT/Util/Finalizer.pm

filter: Statementstmt 96.9% 32 / 33 Branchbran 58.3% 7 / 12 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 90.9% 10 / 11 Podpod 0.0% 0 / 5 totaltotal 75.7% 50 / 66 CC 8 SCAR 10.9
CC
8
Cov
83%
with_select
5.4
DESTROY
4.1
cancel
2.0
CRAP 3.0
« web/cgi-bin/yatt.lib/YATT/Types.pm ↑ Summary web/cgi-bin/yatt.lib/YATT/LRXML.pm »
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
BranchTrueFalseTotal
if ($@) 32 130 162
24 # XXX: This can be hard to catch.
25 32 ▶ syswrite STDOUT, "\n\n[$@]" if $ENV{DEBUG_ERROR};
Branch: 1 branch
BranchTrueFalseTotal
if $ENV{"DEBUG_ERROR"} 0 32 32
26 }
27 162 ▶ my $code = $self->[0] or return;
Branch: 1 branch
BranchTrueFalseTotal
my $code = $self->[0] or return 162 0 162
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
BranchTrueFalseTotal
unless (defined $_[0]) 162 0 162
39 162 ▶ $strref = $_[2] || do {my $str = ""; \$str};
Condition33%1/3
$_[2] || do { my $str = ''; \$str }
l!l&&r!l&&!r
01620
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 }
ABresult
1X1
011
000
40 162 ▶ open $_[0], '>', $strref or die "Can't open strref: $!";
Branch: 1 branch
BranchTrueFalseTotal
open $_[0], ">", $strref or die "Can't open strref: $!" 162 0 162
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
BranchTrueFalseTotal
defined $strref and $$strref 130 0 130
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;
« web/cgi-bin/yatt.lib/YATT/Types.pm ↑ Summary web/cgi-bin/yatt.lib/YATT/LRXML.pm »