XML/Axk/Base.pm

filter: Statementstmt 86.6% 39 / 45 Branchbran 25.0% 1 / 4 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 85.7% 12 / 14 Podpod 0.0% 0 / 2 totaltotal 76.4% 52 / 68 CC 6 SCAR 12.5
CC
6
Cov
78%
any
12.0
now_names
6.0
BEGIN
2.1
CRAP 3.5
« Object/TinyDefaults.pm ↑ Summary XML/Axk/L/LTEST.pm »
1 # XML::Axk::Base: common definitions for axk.
2 # Thanks to David Farrell,
3 # https://www.perl.com/article/how-to-build-a-base-module/
4  
5 package XML::Axk::Base;
6 3 ▶use parent 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use Import::Into;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 # Pragmas
10 3 ▶use 5.020;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use feature ":5.18"; # Use expressly so we can re-export it below
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 # Packages
16 3 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 # Definitions from this file
20 use constant {
21 3 true => !!1,
22 false => !!0,
23  
24 SCRIPT_PKG_PREFIX => 'axk_script_',
25  
26 # When to run an action --- pre, post, or both (CIAO).
27 HI => 2,
28 BYE => 1,
29 CIAO => 0, # the only falsy one
30 3 ▶};
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 3 our @EXPORT = qw(true false HI BYE CIAO);
33 3 our @EXPORT_OK = qw(any SCRIPT_PKG_PREFIX now_names);
34 3 our %EXPORT_TAGS = (
35 default => [@EXPORT],
36 all => [@EXPORT, @EXPORT_OK]
37 );
38  
39 # Uncomment for full stacktraces on all errors
40 BEGIN {
41 3 ▶ $SIG{'__DIE__'} = sub { Carp::confess(@_) } unless $SIG{'__DIE__'};
Subroutine BEGIN: called CC=2 SCAR=7.2
Subroutine __ANON__: called CC=1 SCAR=0.2
Branch: 1 branch
BranchTrueFalseTotal
unless $SIG{"__DIE__"} 3 0 3
42 #$Exporter::Verbose=1;
43 }
44  
45 sub import {
46 21 ▶ my $target = caller;
Subroutine import: called CC=2 SCAR=6.9
47  
48 # Copy symbols listed in @EXPORT first, in case @_ gets trashed later.
49 21 XML::Axk::Base->export_to_level(1, @_);
50  
51 # Re-export pragmas
52 21 feature->import::into($target, qw(:5.18));
53 21 foreach my $pragma (qw(strict warnings)) {
54 42 ${pragma}->import::into($target);
55 };
56  
57 # Re-export packages
58 21 Data::Dumper->import::into($target);
59 21 Carp->import::into($target, qw(carp croak confess));
60  
61 } #import()
62  
63 # # Example of manually copying symbols, for reference
64 # # Copy symbols.
65 # my $caller = caller(0); # get the importing package name
66 # do {
67 # no strict 'refs';
68 # *{"${caller}::true"} = *{"true"};
69 # };
70  
71 # Copied from List::MoreUtils::PP because I don't need anything else
72 # from that package at the moment.
73 sub any (&@)
74 {
75 0 ▶ my $f = shift;
Subroutine any: not called CC=3 SCAR=24.8
Pod undocumented
76 0 foreach (@_)
77 {
78 0 ▶ return 1 if $f->();
Branch: 1 branch
BranchTrueFalseTotal
if &$f() 0 0 0
79 }
80 0 return 0;
81 }
82  
83 # Names of NOW constants, for debugging
84 sub now_names {
85 0 ▶ my %names=(HI,"entering", BYE,"leaving", CIAO,"both");
Subroutine now_names: not called CC=2 SCAR=17.9
Pod undocumented
86 0 ▶ return $names{+shift} || "unknown";
Condition0%0/2
$names{shift()} || 'unknown'
l!l
00
MC/DC0%0/1
$names{shift()} || 'unknown'
$names{shift()}
Truth table0%0/2
A
A= $names{shift()}
Aresult
11
00
87 } # now_names
88  
89 3 1;
90 # vi: set ts=4 sts=4 sw=4 et ai fo-=ro foldmethod=marker ft=perl: #
« Object/TinyDefaults.pm ↑ Summary XML/Axk/L/LTEST.pm »