line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Test::Inline::Content::Simple; |
2
|
|
|
|
|
|
|
# ABSTRACT: Simple templating Content Handler |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
#pod =pod |
5
|
|
|
|
|
|
|
#pod |
6
|
|
|
|
|
|
|
#pod =head1 SYNOPSIS |
7
|
|
|
|
|
|
|
#pod |
8
|
|
|
|
|
|
|
#pod In your inline2test.tpl |
9
|
|
|
|
|
|
|
#pod ---------------------- |
10
|
|
|
|
|
|
|
#pod #!/usr/bin/perl -w |
11
|
|
|
|
|
|
|
#pod |
12
|
|
|
|
|
|
|
#pod use strict; |
13
|
|
|
|
|
|
|
#pod use Test::More [% plan %]; |
14
|
|
|
|
|
|
|
#pod $| = 1; |
15
|
|
|
|
|
|
|
#pod |
16
|
|
|
|
|
|
|
#pod |
17
|
|
|
|
|
|
|
#pod |
18
|
|
|
|
|
|
|
#pod [% tests %] |
19
|
|
|
|
|
|
|
#pod |
20
|
|
|
|
|
|
|
#pod |
21
|
|
|
|
|
|
|
#pod |
22
|
|
|
|
|
|
|
#pod 1; |
23
|
|
|
|
|
|
|
#pod |
24
|
|
|
|
|
|
|
#pod =head1 DESCRIPTION |
25
|
|
|
|
|
|
|
#pod |
26
|
|
|
|
|
|
|
#pod It is relatively common to want to customise the contents of the generated |
27
|
|
|
|
|
|
|
#pod test files to set up custom environment things on an all-scripts basis, |
28
|
|
|
|
|
|
|
#pod rather than file by file (using =begin SETUP blocks). |
29
|
|
|
|
|
|
|
#pod |
30
|
|
|
|
|
|
|
#pod C lets you use a very simple Template Toolkit |
31
|
|
|
|
|
|
|
#pod style template to define this information. |
32
|
|
|
|
|
|
|
#pod |
33
|
|
|
|
|
|
|
#pod It contains only two tags, C and C. |
34
|
|
|
|
|
|
|
#pod |
35
|
|
|
|
|
|
|
#pod The C tag will be inserted as either C 123> or C<'no_plan'>. |
36
|
|
|
|
|
|
|
#pod |
37
|
|
|
|
|
|
|
#pod The C tag will be replaced by the actual testing code. |
38
|
|
|
|
|
|
|
#pod |
39
|
|
|
|
|
|
|
#pod =head1 METHODS |
40
|
|
|
|
|
|
|
#pod |
41
|
|
|
|
|
|
|
#pod =cut |
42
|
|
|
|
|
|
|
|
43
|
12
|
|
|
12
|
|
1056
|
use strict; |
|
12
|
|
|
|
|
26
|
|
|
12
|
|
|
|
|
344
|
|
44
|
12
|
|
|
12
|
|
9478
|
use Path::Tiny (); |
|
12
|
|
|
|
|
125645
|
|
|
12
|
|
|
|
|
378
|
|
45
|
12
|
|
|
12
|
|
94
|
use Params::Util qw{_INSTANCE}; |
|
12
|
|
|
|
|
32
|
|
|
12
|
|
|
|
|
605
|
|
46
|
12
|
|
|
12
|
|
77
|
use Test::Inline::Content (); |
|
12
|
|
|
|
|
25
|
|
|
12
|
|
|
|
|
4362
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
our $VERSION = '2.214'; |
49
|
|
|
|
|
|
|
our @ISA = 'Test::Inline::Content'; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
##################################################################### |
56
|
|
|
|
|
|
|
# Constructor and Accessors |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
#pod =pod |
59
|
|
|
|
|
|
|
#pod |
60
|
|
|
|
|
|
|
#pod =head2 new $filename |
61
|
|
|
|
|
|
|
#pod |
62
|
|
|
|
|
|
|
#pod Manually create a new C object. Takes as |
63
|
|
|
|
|
|
|
#pod parameter a single filename which should contain the template code. |
64
|
|
|
|
|
|
|
#pod |
65
|
|
|
|
|
|
|
#pod Returns a new C object, or C on error. |
66
|
|
|
|
|
|
|
#pod |
67
|
|
|
|
|
|
|
#pod =cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub new { |
70
|
1
|
50
|
|
1
|
1
|
948
|
my $class = ref $_[0] ? ref shift : shift; |
71
|
1
|
50
|
33
|
|
|
32
|
my $file = (defined $_[0] and -r $_[0]) ? shift : return undef; |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# Create the object |
74
|
1
|
50
|
|
|
|
11
|
my $self = $class->SUPER::new() or return undef; |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# Load, check and add the file |
77
|
1
|
50
|
|
|
|
6
|
my $template = Path::Tiny::path($file)->slurp or return undef; |
78
|
1
|
50
|
|
|
|
340
|
$template =~ /\[%\s+tests\s+\%\]/ or return undef; |
79
|
|
|
|
|
|
|
# $template =~ /\[\%\s+plan\s+\%\]/ or return undef; |
80
|
1
|
|
|
|
|
5
|
$self->{template} = $template; |
81
|
|
|
|
|
|
|
|
82
|
1
|
|
|
|
|
3
|
$self; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
#pod =pod |
86
|
|
|
|
|
|
|
#pod |
87
|
|
|
|
|
|
|
#pod =head2 template |
88
|
|
|
|
|
|
|
#pod |
89
|
|
|
|
|
|
|
#pod The C accessor returns the template content for the object |
90
|
|
|
|
|
|
|
#pod |
91
|
|
|
|
|
|
|
#pod =cut |
92
|
|
|
|
|
|
|
|
93
|
1
|
|
|
1
|
1
|
587
|
sub template { $_[0]->{template} } |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
##################################################################### |
100
|
|
|
|
|
|
|
# Test::Inline::Content Methods |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
#pod =pod |
103
|
|
|
|
|
|
|
#pod |
104
|
|
|
|
|
|
|
#pod =head2 process $Inline, $Script |
105
|
|
|
|
|
|
|
#pod |
106
|
|
|
|
|
|
|
#pod The C method is unchanged from C. |
107
|
|
|
|
|
|
|
#pod |
108
|
|
|
|
|
|
|
#pod =cut |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub process { |
111
|
1
|
|
|
1
|
1
|
3
|
my $self = shift; |
112
|
1
|
50
|
|
|
|
11
|
my $Inline = _INSTANCE(shift, 'Test::Inline') or return undef; |
113
|
1
|
50
|
|
|
|
11
|
my $Script = _INSTANCE(shift, 'Test::Inline::Script') or return undef; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Get the merged content |
116
|
1
|
|
|
|
|
4
|
my $content = $Script->merged_content; |
117
|
1
|
50
|
|
|
|
4
|
return undef unless defined $content; |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
# Determine a plan |
120
|
1
|
|
|
|
|
5
|
my $tests = $Script->tests; |
121
|
1
|
50
|
|
|
|
6
|
my $plan = defined $tests |
122
|
|
|
|
|
|
|
? "tests => $tests" |
123
|
|
|
|
|
|
|
: "'no_plan'"; |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# Replace the two values |
126
|
1
|
|
|
|
|
3
|
my $script = $self->{template}; |
127
|
1
|
|
|
|
|
10
|
$script =~ s/\[%\s+tests\s+\%\]/$content/; |
128
|
1
|
|
|
|
|
6
|
$script =~ s/\[\%\s+plan\s+\%\]/$plan/; |
129
|
|
|
|
|
|
|
|
130
|
1
|
|
|
|
|
4
|
$script; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
1; |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
__END__ |