lib/UR/Exit.pm

filter: Statementstmt 43.3% 26 / 60 Branchbran 6.6% 2 / 30 Conditioncond 0.0% 0 / 9 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 75.0% 6 / 8 Podpod 80.0% 4 / 5 totaltotal 32.7% 38 / 116 CC 20 SCAR 44.2
CC
20
Cov
28%
death
151.0
warning
36.0
clean_exit
6.0
CRAP 82.7
« blib/lib/UR/Namespace/Command/Base.pm ↑ Summary lib/UR/Observer.pm »
1 package UR::Exit;
2  
3 =pod
4  
5 =head1 NAME
6  
7 UR::Exit - methods to allow clean application exits.
8  
9 =head1 SYNOPSIS
10  
11 UR::Exit->exit_handler(\&mysub);
12  
13 UR::Exit->clean_exit($value);
14  
15 =head1 DESCRIPTION
16  
17 This module provides the ability to perform certain operations before
18 an application exits.
19  
20 =cut
21  
22 # set up module
23 266 require 5.006_000;
24 266 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 266 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 266 require UR;
27 266 our $VERSION = "0.47"; # UR $VERSION;
28 266 our (@ISA, @EXPORT, @EXPORT_OK);
29  
30 266 require Exporter;
31 266 @ISA = qw(Exporter);
32 266 @EXPORT = qw();
33 266 @EXPORT_OK = qw();
34  
35 266 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
36  
37  
38 =pod
39  
40 =head1 METHODS
41  
42 These methods provide exit functionality.
43  
44 =over 4
45  
46 =item exit_handler
47  
48 UR::Exit->exit_handler(\&mysub);
49  
50 Specifies that a given subroutine be run when the application exits.
51 (Unimplimented!)
52  
53 =cut
54  
55 sub exit_handler
56 0 ▶{
Subroutine exit_handler: not called CC=1 SCAR=6.9
Pod documented
57 0 die "Unimplimented";
58 }
59  
60 =pod
61  
62 =item clean_exit
63  
64 UR::Exit->clean_exit($value);
65  
66 Exit the application, running all registered subroutines.
67 (Unimplimented! Just exits the application directly.)
68  
69 =cut
70  
71 sub clean_exit
72 0 ▶{
Subroutine clean_exit: not called CC=2 SCAR=17.9
Pod documented
73 0 my $class = shift;
74 0 my ($value) = @_;
75 0 ▶ $value = 0 unless defined($value);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 0 0 0
76 0 exit($value);
77 }
78  
79 =pod
80  
81 =item death
82  
83 Catch any die or warn calls. This is a universal place to catch die
84 and warn if debugging.
85  
86 =cut
87  
88 sub death
89 1441 ▶{
Subroutine death: called CC=13 SCAR=50.2
Pod documented
90 1441 ▶ unless ($ENV{'UR_STACK_DUMP_ON_DIE'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"UR_STACK_DUMP_ON_DIE"}) 1441 0 1441
91 1441 return;
92 }
93  
94 # workaround common error
95 0 ▶ if ($_[0] =~ /Can.*t upgrade that kind of scalar during global destruction/)
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /Can.*t upgrade that kind of scalar during global destruction/) 0 0 0
96 {
97 0 exit 1;
98 }
99  
100 0 ▶ if (defined $^S) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $^S) { } 0 0 0
101 # $^S is defined when perl is executing (as opposed to interpreting)
102 0 ▶ if ($^S) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^S) 0 0 0
103 # $^S is true when its executing in an eval, false outside of one
104 0 return;
105 }
106 } else {
107 # interpreter is parsing a module or string eval
108 # check the call stack depth for up-stream evals
109 # fall back to perls default handler if there is one
110 0 my $call_stack_depth = 0;
111 0 for (1) {
112 0 my @details = caller($call_stack_depth);
113 #print Data::Dumper::Dumper(\@details);
114 0 ▶ last if scalar(@details) == 0;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @details == 0 0 0 0
115  
116 0 ▶ if ($details[1] =~ /\(eval .*\)/) {
Branch: 2 branches
BranchTrueFalseTotal
if ($details[1] =~ /\(eval .*\)/) { } 0 0 0
elsif ($details[3] eq '(eval)') { } 0 0 0
117 #print "<no carp due to eval string>";
118 0 return;
119 }
120 elsif ($details[3] eq "(eval)") {
121 #print "<no carp due to eval block>";
122 0 return;
123 }
124 0 $call_stack_depth++;
125 0 redo;
126 }
127 }
128  
129 0 ▶ if
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /\n$/ and UNIVERSAL::can('UR::Context::Process', 'is_initialized') and defined 'UR::Context::Process'->is_initialized and 'UR::Context::Process'->is_initialized == 1) { } 0 0 0
Condition0%0/9
$_[0] =~ /\n$/ and UNIVERSAL::can("UR::Context::Process", "is_initialized") and defined "UR::Context::Process"->is_initialized and "UR::Context::Process"->is_initialized == 1
!ll&&!rl&&r
000
$_[0] =~ /\n$/ and UNIVERSAL::can("UR::Context::Process", "is_initialized") and defined "UR::Context::Process"->is_initialized
!ll&&!rl&&r
000
$_[0] =~ /\n$/ and UNIVERSAL::can("UR::Context::Process", "is_initialized")
!ll&&!rl&&r
000
MC/DC0%0/4
$_[0] =~ /\n$/ and UNIVERSAL::can("UR::Context::Process", "is_initialized") and defined "UR::Context::Process"->is_initialized and "UR::Context::Process"->is_initialized == 1
$_[0] =~ /\n$/ UNIVERSAL::can("UR::Context::Process", "is_initialized") defined "UR::Context::Process"->is_initialized "UR::Context::Process"->is_initialized == 1
Truth table0%0/5
A and B and C and D
A= $_[0] =~ /\n$/B= UNIVERSAL::can("UR::Context::Process", "is_initialized")C= defined "UR::Context::Process"->is_initializedD= "UR::Context::Process"->is_initialized == 1
ABCDresult
0XXX0
10XX0
110X0
11100
11111
130 (
131 $_[0] =~ /\n$/
132 and UNIVERSAL::can("UR::Context::Process","is_initialized")
133 and defined(UR::Context::Process->is_initialized)
134 and (UR::Context::Process->is_initialized == 1)
135 )
136 {
137 # Do normal death if there is a newline at the end, and all other
138 # things are sane.
139 0 return;
140 }
141 else
142 {
143 # Dump the call stack in other cases.
144 # This is a developer error occurring while things are
145 # initializing.
146 0 local $Carp::CarpLevel = 1;
147 0 Carp::confess(@_);
148 0 return;
149 }
150 }
151  
152 =pod
153  
154 =item warning
155  
156 Give more informative warnings.
157  
158 =cut
159  
160 sub warning
161 533 ▶{
Subroutine warning: called CC=7 SCAR=35.8
Pod documented
162  
163 533 ▶ unless ($ENV{'UR_STACK_DUMP_ON_WARN'}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($ENV{"UR_STACK_DUMP_ON_WARN"}) 533 0 533
164 533 warn @_;
165 533 return;
166 }
167  
168 0 ▶ return if $_[0] =~ /Attempt to free unreferenced scalar/;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /Attempt to free unreferenced scalar/ 0 0 0
169 0 ▶ return if $_[0] =~ /Use of uninitialized value in exit at/;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /Use of uninitialized value in exit at/ 0 0 0
170 0 ▶ return if $_[0] =~ /Use of uninitialized value in subroutine entry at/;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /Use of uninitialized value in subroutine entry at/ 0 0 0
171 0 ▶ return if $_[0] =~ /One or more DATA sections were not processed by Inline/;
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] =~ /One or more DATA sections were not processed by Inline/ 0 0 0
172 0 UR::ModuleBase->warning_message(@_);
173 0 ▶ if ($_[0] =~ /Deep recursion on subroutine/)
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /Deep recursion on subroutine/) 0 0 0
174 {
175 0 print STDERR "Forced exit by UR::Exit on deep recursion.\n";
176 0 print STDERR Carp::longmess("Stack tail:");
177 0 exit 1;
178 }
179 0 return;
180 }
181  
182 #$SIG{__DIE__} = \&death unless ($SIG{__DIE__});
183 #$SIG{__WARN__} = \&warning unless ($SIG{__WARN__});
184  
185 266 ▶sub enable_hooks_for_warn_and_die {
Subroutine enable_hooks_for_warn_and_die: called CC=1 SCAR=0.0
Pod undocumented
186 266 $SIG{__DIE__} = \&death;
187 266 $SIG{__WARN__} = \&warning;
188 }
189  
190 266 &enable_hooks_for_warn_and_die();
191  
192  
193 266 1;
194 __END__
« blib/lib/UR/Namespace/Command/Base.pm ↑ Summary lib/UR/Observer.pm »