AgainstSchema.pm

filter: Statementstmt 92.3% 36 / 39 Branchbran 66.6% 4 / 6 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 84.7% 50 / 59 CC 6 SCAR 12.5
CC
6
Cov
85%
import
6.8
BEGIN
1.0
BEGIN
1.0
CRAP 3.5
« AgainstSchema/XML.pm ↑ Summary
1 ###############################################################################
2 #
3 # This file copyright (c) 2011 by Randy J. Ray, all rights reserved.
4 #
5 # See LICENSE AND COPYRIGHT in the documentation for redistribution terms.
6 #
7 ###############################################################################
8 #
9 # Description: This is an umbrella of sorts, that allows users to make
10 # use of multiple Test::AgainstSchema::* implementation
11 # classes at once, while also still getting all the benefits
12 # of being a subclass of Test::Builder::Module.
13 #
14 # Functions: import
15 #
16 # Libraries: Test::Builder::Module
17 #
18 # Global Consts: $VERSION
19 #
20 ###############################################################################
21  
22 package Test::AgainstSchema;
23  
24 2 ▶use 5.008;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use vars qw($VERSION);
Subroutine BEGIN: called CC=1 SCAR=0.0
28 2 ▶use subs qw(import);
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 ▶use base 'Test::Builder::Module';
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 2 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 2 $VERSION = '0.100';
34 2 $VERSION = eval $VERSION; ## no critic(ProhibitStringyEval)
35  
36 ###############################################################################
37 #
38 # Sub Name: import
39 #
40 # Description: Facilitate the loading of any specialization classes into
41 # the namespace of our caller.
42 #
43 # Arguments: NAME IN/OUT TYPE DESCRIPTION
44 # $class in scalar Class we're called from
45 # @rest in array Rest of the args-list
46 #
47 # Returns: threads through to SUPER::import()
48 #
49 ###############################################################################
50 sub import
51 2 ▶{
Subroutine import: called CC=6 SCAR=19.2
52 2 my ($class, @rest) = @_;
53  
54 # Yes, this means we will be force-exporting other modules' export lists
55 # into the namespace of whoever called us.
56 2 my $caller = caller 0;
57  
58 # This is tricky. Anything that might be an import argument to
59 # Test::Builder::Module has to stay. Things that look like they are
60 # specializations of Test::AgainstSchema need to be handled here. For now,
61 # at least until the first bugs appear on RT, assume any string that leads
62 # with an upper-case letter is meant for us.
63 2 my @pass = ();
64 2 for my $opt (@rest)
65 {
66 # I explicitly want the [A-Z] range here, not [[:upper:]]. This is
67 # referring to a class that will be eventually loaded, so it isn't
68 # covered by the full Unicode range.
69 ## no critic(ProhibitEnumeratedClasses)
70 2 ▶ if (ref($opt) || ($opt !~ /^[A-Z]/))
Branch: 1 branch
BranchTrueFalseTotal
if (ref $opt or not $opt =~ /^[A-Z]/) 0 2 2
Condition33%1/3
ref $opt or not $opt =~ /^[A-Z]/
l!l&&r!l&&!r
002
MC/DC0%0/2
ref $opt or not $opt =~ /^[A-Z]/
ref $opt not $opt =~ /^[A-Z]/
Truth table33%1/3
A or not(B)
A= ref $optB= not $opt =~ /^[A-Z]/
ABresult
1X1
011
000
71 {
72 # Assume that this option is intended for the superclass
73 0 push @pass, $opt;
74 0 next;
75 }
76  
77 # If the name doesn't begin with "Test::", then it is assumed to be
78 # relative to this class. Prepend $class to it in that case. This
79 # lets format-testing modules that aren't directly under
80 # Test::AgainstSchema::* be covered by our umbrella.
81 2 ▶ if ($opt !~ /^Test::/)
Branch: 1 branch
BranchTrueFalseTotal
unless ($opt =~ /^Test::/) 1 1 2
82 {
83 1 $opt = "${class}::$opt";
84 }
85  
86 # Attempt to load it, importing what it offers into the namespace that
87 # called us.
88 ## no critic(ProhibitStringyEval)
89 2 ▶ my $ret = eval "package $caller; use $opt; 1;";
Subroutine BEGIN: called CC=1 SCAR=0.0
90 2 ▶ if (! $ret)
Branch: 1 branch
BranchTrueFalseTotal
unless ($ret) 0 2 2
91 {
92 0 croak "$class: Error loading format-tester $opt: $@";
93 }
94 }
95  
96 2 return $class->SUPER::import(@pass);
97 }
98  
99 2 1;
100  
101 __END__
« AgainstSchema/XML.pm ↑ Summary