| 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
Condition33%1/3
ref $opt or not $opt =~ /^[A-Z]/
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]/
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||