blib/lib/Mason/t/Plugins.pm

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