root/Encode-DoubleEncodedUTF8/trunk/inc/Test/Builder/Module.pm

Revision 2162 (checked in by miyagawa, 13 years ago)

import

Line 
1 #line 1
2 package Test::Builder::Module;
3
4 use Test::Builder;
5
6 require Exporter;
7 @ISA = qw(Exporter);
8
9 $VERSION = '0.04';
10
11 use strict;
12
13 # 5.004's Exporter doesn't have export_to_level.
14 my $_export_to_level = sub {
15       my $pkg = shift;
16       my $level = shift;
17       (undef) = shift;                  # redundant arg
18       my $callpkg = caller($level);
19       $pkg->export($callpkg, @_);
20 };
21
22
23 #line 82
24
25 sub import {
26     my($class) = shift;
27
28     my $test = $class->builder;
29
30     my $caller = caller;
31
32     $test->exported_to($caller);
33
34     $class->import_extra(\@_);
35     my(@imports) = $class->_strip_imports(\@_);
36
37     $test->plan(@_);
38
39     $class->$_export_to_level(1, $class, @imports);
40 }
41
42
43 sub _strip_imports {
44     my $class = shift;
45     my $list  = shift;
46
47     my @imports = ();
48     my @other   = ();
49     my $idx = 0;
50     while( $idx <= $#{$list} ) {
51         my $item = $list->[$idx];
52
53         if( defined $item and $item eq 'import' ) {
54             push @imports, @{$list->[$idx+1]};
55             $idx++;
56         }
57         else {
58             push @other, $item;
59         }
60
61         $idx++;
62     }
63
64     @$list = @other;
65
66     return @imports;
67 }
68
69
70 #line 144
71
72 sub import_extra {}
73
74
75 #line 175
76
77 sub builder {
78     return Test::Builder->new;
79 }
80
81
82 1;
Note: See TracBrowser for help on using the browser.