line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Eve::TemplateStub; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
5846
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
906
|
use Test::MockObject; |
|
1
|
|
|
|
|
3179
|
|
|
1
|
|
|
|
|
7
|
|
7
|
1
|
|
|
1
|
|
1081
|
use Test::MockObject::Extends; |
|
1
|
|
|
|
|
4217
|
|
|
1
|
|
|
|
|
9
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
107
|
use Digest::MD5 (); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
24
|
|
10
|
1
|
|
|
1
|
|
1068
|
use Data::Dumper; |
|
1
|
|
|
|
|
14728
|
|
|
1
|
|
|
|
|
466
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $stash_stub = {}; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 NAME |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
B - a stub class that replaces the template class |
17
|
|
|
|
|
|
|
with a mock. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 SYNOPSIS |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
use Eve::TemplateStub; |
22
|
|
|
|
|
|
|
use Eve::Template; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
my $mocked_template = Eve::Template->new( |
25
|
|
|
|
|
|
|
path => $path_string, |
26
|
|
|
|
|
|
|
compile_path => $compile_path_string, |
27
|
|
|
|
|
|
|
expiration_interval => $interval_value); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
my $output = $template->process( |
30
|
|
|
|
|
|
|
file => $file_name, var_hash => $var_hash); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 DESCRIPTION |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
B is a class that provides a mocked template object |
35
|
|
|
|
|
|
|
with limited stubbed templating functionality.. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 METHODS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 B |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Returns a mocked B object. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub mock_template { |
46
|
5
|
|
|
5
|
1
|
14
|
my @args = @_; |
47
|
|
|
|
|
|
|
|
48
|
5
|
|
|
|
|
45
|
my $template_mock = Test::MockObject::Extends->new('Template'); |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
$template_mock->mock( |
51
|
|
|
|
|
|
|
'new', |
52
|
|
|
|
|
|
|
sub { |
53
|
5
|
|
|
5
|
|
681
|
my ($self, undef, $arg_hash) = @_; |
54
|
|
|
|
|
|
|
|
55
|
5
|
|
|
|
|
9
|
my $result = $self; |
56
|
5
|
100
|
|
|
|
56
|
if ($arg_hash->{'INCLUDE_PATH'} eq '/some/buggy/path') { |
57
|
1
|
|
|
|
|
3
|
$result = undef |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
5
|
|
|
|
|
54
|
return $result; |
61
|
5
|
|
|
|
|
782
|
}); |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$template_mock->mock( |
64
|
5
|
|
|
1
|
|
223
|
'error', sub { return 'Oops'; }); |
|
1
|
|
|
|
|
54
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
$template_mock->mock( |
67
|
|
|
|
|
|
|
'process', |
68
|
|
|
|
|
|
|
sub { |
69
|
3
|
|
|
3
|
|
696
|
my (undef, $file, $var_hash, $output_ref) = @_; |
70
|
|
|
|
|
|
|
|
71
|
3
|
|
|
|
|
8
|
my $result = 1; |
72
|
3
|
100
|
|
|
|
12
|
if ($file eq 'buggy.html') { |
73
|
1
|
|
|
|
|
3
|
$result = undef; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
3
|
50
|
|
|
|
19
|
if ($file eq 'empty.html') { |
|
|
50
|
|
|
|
|
|
77
|
0
|
|
|
|
|
0
|
${$output_ref} = ''; |
|
0
|
|
|
|
|
0
|
|
78
|
|
|
|
|
|
|
} elsif ($file eq 'dump.html') { |
79
|
0
|
|
|
|
|
0
|
local $Data::Dumper::Maxdepth = 2; |
80
|
0
|
|
|
|
|
0
|
${$output_ref} = Dumper($var_hash); |
|
0
|
|
|
|
|
0
|
|
81
|
|
|
|
|
|
|
} else { |
82
|
3
|
|
|
|
|
5
|
delete $var_hash->{'matches_hash'}; |
83
|
3
|
|
|
|
|
18
|
${$output_ref} = Digest::MD5::md5_hex(Dumper($file, $var_hash)); |
|
3
|
|
|
|
|
619
|
|
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
3
|
|
|
|
|
226
|
return $result; |
87
|
5
|
|
|
|
|
166
|
}); |
88
|
|
|
|
|
|
|
|
89
|
5
|
|
|
|
|
149
|
return $template_mock->new(@args); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 B |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=cut |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub main { |
97
|
|
|
|
|
|
|
Test::MockObject::Extends->new('Template')->fake_module( |
98
|
5
|
|
|
5
|
1
|
21
|
'Template', 'new' => sub { return mock_template(@_); }); |
|
1
|
|
|
1
|
|
13
|
|
99
|
|
|
|
|
|
|
Test::MockObject::Extends->new('Template')->fake_module( |
100
|
1
|
|
|
7
|
|
68845
|
'Template::Stash::XS', 'new' => sub { return $stash_stub; }); |
|
7
|
|
|
|
|
197
|
|
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
main(); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head1 SEE ALSO |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=over 4 |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=item L |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=item L |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=back |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Copyright 2010-2013 Sergey Konoplev, Igor Zinovyev. |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
120
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
121
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 AUTHOR |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=over 4 |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=item L |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=item L |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=back |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=cut |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
1; |