line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mason::t::Plugins; ## no critic (Moose::RequireMakeImmutable) |
2
|
|
|
|
|
|
|
$Mason::t::Plugins::VERSION = '2.22'; |
3
|
1
|
|
|
1
|
|
1576
|
use Test::Class::Most parent => 'Mason::Test::Class'; |
|
1
|
|
|
|
|
39243
|
|
|
1
|
|
|
|
|
6
|
|
4
|
|
|
|
|
|
|
use Capture::Tiny qw(capture_merged); |
5
|
|
|
|
|
|
|
use Mason::Util qw(dump_one_line); |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub test_notify_plugin : Tests { |
8
|
|
|
|
|
|
|
my $self = shift; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
$self->setup_interp( |
11
|
|
|
|
|
|
|
plugins => ['+Mason::Test::Plugins::Notify'], |
12
|
|
|
|
|
|
|
no_source_line_numbers => 1, |
13
|
|
|
|
|
|
|
); |
14
|
|
|
|
|
|
|
$self->add_comp( path => '/test_plugin_support.mi', src => 'hi' ); |
15
|
|
|
|
|
|
|
my $output = capture_merged { |
16
|
|
|
|
|
|
|
$self->test_comp( |
17
|
|
|
|
|
|
|
path => '/test_plugin.mc', |
18
|
|
|
|
|
|
|
src => '<& test_plugin_support.mi &>', |
19
|
|
|
|
|
|
|
expect => 'hi' |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
}; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $like = sub { my $regex = shift; like( $output, $regex, $regex ) }; |
24
|
|
|
|
|
|
|
$like->(qr/starting interp run/); |
25
|
|
|
|
|
|
|
$like->(qr/starting request run - \/test_plugin/); |
26
|
|
|
|
|
|
|
$like->(qr/starting request comp - test_plugin_support.mi/); |
27
|
|
|
|
|
|
|
$like->(qr/starting compilation parse - \/test_plugin.mc/); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Call Mason::Test::RootClass->new, then make base classes like |
31
|
|
|
|
|
|
|
# Mason::Test::RootClass::Interp are used automatically |
32
|
|
|
|
|
|
|
# |
33
|
|
|
|
|
|
|
sub test_notify_root_class : Tests { |
34
|
|
|
|
|
|
|
my $self = shift; |
35
|
|
|
|
|
|
|
my $mrc = 'Mason::Test::RootClass'; |
36
|
|
|
|
|
|
|
$self->setup_interp( mason_root_class => $mrc ); |
37
|
|
|
|
|
|
|
is( $self->interp->mason_root_class, $mrc, "mason_root_class" ); |
38
|
|
|
|
|
|
|
is( $self->interp->base_compilation_class, "${mrc}::Compilation", "base_compilation_class" ); |
39
|
|
|
|
|
|
|
is( $self->interp->base_component_class, "${mrc}::Component", "base_component_class" ); |
40
|
|
|
|
|
|
|
is( $self->interp->base_request_class, "${mrc}::Request", "base_request_class" ); |
41
|
|
|
|
|
|
|
is( $self->interp->base_result_class, "Mason::Result", "base_result_class" ); |
42
|
|
|
|
|
|
|
isa_ok( $self->interp, "${mrc}::Interp", "base_interp_class" ); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$self->add_comp( path => '/test_plugin_support.mi', src => 'hi' ); |
45
|
|
|
|
|
|
|
my $output = capture_merged { |
46
|
|
|
|
|
|
|
$self->test_comp( |
47
|
|
|
|
|
|
|
path => '/test_plugin.mc', |
48
|
|
|
|
|
|
|
src => '<& test_plugin_support.mi &>', |
49
|
|
|
|
|
|
|
expect => 'hi' |
50
|
|
|
|
|
|
|
); |
51
|
|
|
|
|
|
|
}; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $like = sub { my $regex = shift; like( $output, $regex, $regex ) }; |
54
|
|
|
|
|
|
|
$like->(qr/starting interp run/); |
55
|
|
|
|
|
|
|
$like->(qr/starting request run - \/test_plugin/); |
56
|
|
|
|
|
|
|
$like->(qr/starting request comp - test_plugin_support.mi/); |
57
|
|
|
|
|
|
|
$like->(qr/starting compilation parse - \/test_plugin.mc/); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub test_strict_plugin : Tests { |
61
|
|
|
|
|
|
|
my $self = shift; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
$self->setup_interp( |
64
|
|
|
|
|
|
|
base_component_moose_class => 'Mason::Test::Overrides::Component::StrictMoose', ); |
65
|
|
|
|
|
|
|
$self->add_comp( path => '/test_strict_plugin.mc', src => 'hi' ); |
66
|
|
|
|
|
|
|
lives_ok { $self->interp->run('/test_strict_plugin') }; |
67
|
|
|
|
|
|
|
throws_ok { $self->interp->run( '/test_strict_plugin', foo => 5 ) } qr/Found unknown attribute/; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
{ |
71
|
|
|
|
|
|
|
package Mason::Test::Plugins::A; |
72
|
|
|
|
|
|
|
$Mason::Test::Plugins::A::VERSION = '2.22'; |
73
|
|
|
|
|
|
|
use Moose; |
74
|
|
|
|
|
|
|
with 'Mason::Plugin'; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
{ |
77
|
|
|
|
|
|
|
package Mason::Plugin::B; |
78
|
|
|
|
|
|
|
$Mason::Plugin::B::VERSION = '2.22'; |
79
|
|
|
|
|
|
|
use Moose; |
80
|
|
|
|
|
|
|
with 'Mason::Plugin'; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
{ |
83
|
|
|
|
|
|
|
package Mason::Plugin::C; |
84
|
|
|
|
|
|
|
$Mason::Plugin::C::VERSION = '2.22'; |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
use Moose; |
87
|
|
|
|
|
|
|
with 'Mason::Plugin'; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
{ |
90
|
|
|
|
|
|
|
package Mason::Plugin::D; |
91
|
|
|
|
|
|
|
$Mason::Plugin::D::VERSION = '2.22'; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
use Moose; |
94
|
|
|
|
|
|
|
with 'Mason::Plugin'; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
{ |
97
|
|
|
|
|
|
|
package Mason::Plugin::E; |
98
|
|
|
|
|
|
|
$Mason::Plugin::E::VERSION = '2.22'; |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
use Moose; |
101
|
|
|
|
|
|
|
with 'Mason::Plugin'; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
{ |
104
|
|
|
|
|
|
|
package Mason::PluginBundle::F; |
105
|
|
|
|
|
|
|
$Mason::PluginBundle::F::VERSION = '2.22'; |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
use Moose; |
108
|
|
|
|
|
|
|
with 'Mason::PluginBundle'; |
109
|
|
|
|
|
|
|
sub requires_plugins { return qw(C D) } |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
{ |
112
|
|
|
|
|
|
|
package Mason::Test::PluginBundle::G; |
113
|
|
|
|
|
|
|
$Mason::Test::PluginBundle::G::VERSION = '2.22'; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
use Moose; |
116
|
|
|
|
|
|
|
with 'Mason::PluginBundle'; |
117
|
|
|
|
|
|
|
sub requires_plugins { return qw(C E) } |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
{ |
120
|
|
|
|
|
|
|
package Mason::Plugin::H; |
121
|
|
|
|
|
|
|
$Mason::Plugin::H::VERSION = '2.22'; |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
use Moose; |
124
|
|
|
|
|
|
|
with 'Mason::Plugin'; |
125
|
|
|
|
|
|
|
sub requires_plugins { return qw(@F) } |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
{ |
128
|
|
|
|
|
|
|
package Mason::PluginBundle::I; |
129
|
|
|
|
|
|
|
$Mason::PluginBundle::I::VERSION = '2.22'; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
use Moose; |
132
|
|
|
|
|
|
|
with 'Mason::PluginBundle'; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub requires_plugins { |
135
|
|
|
|
|
|
|
return ( '+Mason::Test::Plugins::A', 'B', '@F', '+Mason::Test::PluginBundle::G', ); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
{ |
140
|
|
|
|
|
|
|
package Mason::PluginBundle::J; |
141
|
|
|
|
|
|
|
$Mason::PluginBundle::J::VERSION = '2.22'; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
use Moose; |
144
|
|
|
|
|
|
|
with 'Mason::PluginBundle'; |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
sub requires_plugins { |
147
|
|
|
|
|
|
|
return ('@I'); |
148
|
|
|
|
|
|
|
} |
149
|
|
|
|
|
|
|
} |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub test_plugin_specs : Tests { |
152
|
|
|
|
|
|
|
my $self = shift; |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
require Mason::PluginBundle::Default; |
155
|
|
|
|
|
|
|
my @default_plugins = Mason::PluginBundle::Default->requires_plugins |
156
|
|
|
|
|
|
|
or die "no default plugins"; |
157
|
|
|
|
|
|
|
my $test = sub { |
158
|
|
|
|
|
|
|
my ( $plugin_list, $expected_plugins ) = @_; |
159
|
|
|
|
|
|
|
my $interp = Mason->new( comp_root => $self->comp_root, plugins => $plugin_list ); |
160
|
|
|
|
|
|
|
my $got_plugins = |
161
|
|
|
|
|
|
|
[ map { /Mason::Plugin::/ ? substr( $_, 15 ) : $_ } @{ $interp->plugins } ]; |
162
|
|
|
|
|
|
|
cmp_deeply( |
163
|
|
|
|
|
|
|
$got_plugins, |
164
|
|
|
|
|
|
|
[ @$expected_plugins, @default_plugins ], |
165
|
|
|
|
|
|
|
dump_one_line($plugin_list) |
166
|
|
|
|
|
|
|
); |
167
|
|
|
|
|
|
|
}; |
168
|
|
|
|
|
|
|
$test->( [], [] ); |
169
|
|
|
|
|
|
|
$test->( ['E'], ['E'] ); |
170
|
|
|
|
|
|
|
$test->( ['H'], [ 'H', 'C', 'D' ] ); |
171
|
|
|
|
|
|
|
$test->( ['@F'], [ 'C', 'D' ] ); |
172
|
|
|
|
|
|
|
$test->( ['@I'], [ 'Mason::Test::Plugins::A', 'B', 'C', 'D', 'E' ] ); |
173
|
|
|
|
|
|
|
$test->( [ '-C', '@I', '-+Mason::Test::Plugins::A' ], [ 'B', 'D', 'E' ] ); |
174
|
|
|
|
|
|
|
$test->( [ '-@I', '@J' ], [] ); |
175
|
|
|
|
|
|
|
throws_ok { $test->( ['@X'] ) } qr/could not load 'Mason::PluginBundle::X'/; |
176
|
|
|
|
|
|
|
throws_ok { $test->( ['Y'] ) } qr/could not load 'Mason::Plugin::Y'/; |
177
|
|
|
|
|
|
|
} |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
{ |
180
|
|
|
|
|
|
|
package Mason::Test::Plugins::Upper; |
181
|
|
|
|
|
|
|
$Mason::Test::Plugins::Upper::VERSION = '2.22'; |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
use Moose; |
184
|
|
|
|
|
|
|
with 'Mason::Plugin' |
185
|
|
|
|
|
|
|
} |
186
|
|
|
|
|
|
|
{ |
187
|
|
|
|
|
|
|
package Mason::Test::Plugins::Upper::Request; |
188
|
|
|
|
|
|
|
$Mason::Test::Plugins::Upper::Request::VERSION = '2.22'; |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
use Mason::PluginRole; |
191
|
|
|
|
|
|
|
after 'process_output' => sub { |
192
|
|
|
|
|
|
|
my ( $self, $bufref ) = @_; |
193
|
|
|
|
|
|
|
$$bufref = uc($$bufref); |
194
|
|
|
|
|
|
|
}; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
sub test_process_output_plugin : Tests { |
198
|
|
|
|
|
|
|
my $self = shift; |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
$self->setup_interp( plugins => ['+Mason::Test::Plugins::Upper'] ); |
201
|
|
|
|
|
|
|
$self->test_comp( src => 'Hello', expect => 'HELLO' ); |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
1; |