File Coverage

blib/lib/Test/Formats.pm
Criterion Covered Total %
statement 20 26 76.9
branch 0 6 0.0
condition 0 3 0.0
subroutine 6 6 100.0
pod n/a
total 26 41 63.4


line stmt bran cond sub pod time code
1             ###############################################################################
2             #
3             # This file copyright (c) 2008 by Randy J. Ray, all rights reserved.
4             #
5             # See LICENSE in the documentation for redistribution terms.
6             #
7             ###############################################################################
8             #
9             # $Id: Formats.pm 2 2008-10-20 09:56:47Z rjray $
10             #
11             # Description: This is an umbrella of sorts, that allows users to make
12             # use of multiple Test::Formats::* implementation classes
13             # at once, while also still getting all the benefits of
14             # being a subclass of Test::Builder::Module.
15             #
16             # Functions: import
17             #
18             # Libraries: Test::Builder::Module
19             #
20             # Global Consts: $VERSION
21             #
22             ###############################################################################
23              
24             package Test::Formats;
25              
26 2     2   7105 use 5.008;
  2         8  
  2         68  
27 2     2   10 use strict;
  2         4  
  2         64  
28 2     2   74 use warnings;
  2         4  
  2         57  
29 2     2   1609 use subs qw(import);
  2         32  
  2         10  
30 2     2   68 use base 'Test::Builder::Module';
  2         3  
  2         505  
31              
32             our $VERSION = '0.10';
33              
34             ###############################################################################
35             #
36             # Sub Name: import
37             #
38             # Description: Do some sleight-of-hand with @ISA during the import
39             # stage.
40             #
41             # Arguments: NAME IN/OUT TYPE DESCRIPTION
42             # $class in scalar Class we're called from
43             # @rest in array Rest of the args-list
44             #
45             # Globals: @ISA
46             #
47             # Returns: threads through to SUPER::import()
48             #
49             ###############################################################################
50             sub import
51             {
52 1     1   7 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 1         1 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::Formats need to be handled here. For now, at
61             # least until the first bugs appear on RT, assume any string that leads
62             # with an upper-case letter is meant for us.
63 1         2 my @pass = ();
64 1         2 for my $opt (@rest)
65             {
66 0 0 0     0 if (ref($opt) || ($opt !~ /^[A-Z]/))
67             {
68             # Assume that this option is intended for the superclass
69 0         0 push @pass, $opt;
70 0         0 next;
71             }
72              
73             # If the name doesn't begin with "Test::", then it is assumed to be
74             # relative to this class. Prepend $class to it in that case. This
75             # lets format-testing modules that aren't directly under
76             # Test::Formats::* be covered by our umbrella.
77 0 0       0 $opt = "${class}::$opt" unless $opt =~ /^Test::/;
78              
79             # Attempt to load it, importing what it offers into the namespace that
80             # called us.
81 0         0 eval "package $caller; use $opt;";
82 0 0       0 die "$class: Error loading format-tester $opt: $@" if $@;
83             }
84              
85 1         9 $class->SUPER::import(@pass);
86             }
87              
88             1;
89              
90             __END__