| 1 | package Mason::t::Autobase; | ||||||||||
| 2 | 1 | $Mason::t::Autobase::VERSION = '2.24'; | |||||||||
| 3 | 1 | ▶ | use Test::Class::Most parent => 'Mason::Test::Class'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | sub test_autobase : Tests { | ||||||||
|
Subroutine
test_autobase: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 6 | 1 | my $self = shift; | |||||||||
| 7 | 1 | my $interp = $self->interp; | |||||||||
| 8 | |||||||||||
| 9 | 24 | ▶ | my $check_parent = sub { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||
| 10 | 24 | my ( $path, $parent ) = @_; | |||||||||
| 11 | |||||||||||
| 12 | 24 | ▶ | my $base_comp_class = $interp->load($path) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 13 | or die "could not load '$path'"; | ||||||||||
| 14 | 24 | ▶ | my $parent_comp_class = ( $parent =~ /\// ) ? $interp->load($parent) : $parent; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 15 | 24 | cmp_deeply( [ $base_comp_class->meta->superclasses ], | |||||||||
| 16 | [$parent_comp_class], "parent of $path is $parent" ); | ||||||||||
| 17 | 1 | }; | |||||||||
| 18 | |||||||||||
| 19 | 12 | ▶ | my $add = sub { | ||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||
| 20 | 12 | my ( $path, $extends ) = @_; | |||||||||
| 21 | |||||||||||
| 22 | 12 | ▶ | $self->add_comp( | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | path => $path, | ||||||||||
| 24 | src => ( $extends ? "<%flags>\nextends => $extends\n</%flags>" : " " ) | ||||||||||
| 25 | ); | ||||||||||
| 26 | 1 | }; | |||||||||
| 27 | |||||||||||
| 28 | 4 | ▶ | my $remove = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 29 | 4 | my ($path) = @_; | |||||||||
| 30 | |||||||||||
| 31 | 4 | $self->remove_comp( path => $path, ); | |||||||||
| 32 | 1 | }; | |||||||||
| 33 | |||||||||||
| 34 | # Add components with no autobases, make sure they inherit from | ||||||||||
| 35 | # Mason::Component | ||||||||||
| 36 | # | ||||||||||
| 37 | 1 | $add->('/comp.mc'); | |||||||||
| 38 | 1 | $add->('/foo/comp.mc'); | |||||||||
| 39 | 1 | $add->('/foo/bar/comp.mc'); | |||||||||
| 40 | 1 | $add->('/foo/bar/baz/comp.mc'); | |||||||||
| 41 | |||||||||||
| 42 | 1 | my $base_class = $self->interp->component_class; | |||||||||
| 43 | |||||||||||
| 44 | 1 | $check_parent->( '/comp.mc', $base_class ); | |||||||||
| 45 | 1 | $check_parent->( '/foo/comp.mc', $base_class ); | |||||||||
| 46 | 1 | $check_parent->( '/foo/bar/comp.mc', $base_class ); | |||||||||
| 47 | 1 | $check_parent->( '/foo/bar/baz/comp.mc', $base_class ); | |||||||||
| 48 | |||||||||||
| 49 | # Add autobases, test the parents of the components and autobases | ||||||||||
| 50 | # | ||||||||||
| 51 | 1 | $add->('/Base.mc'); | |||||||||
| 52 | 1 | $add->('/foo/Base.mc'); | |||||||||
| 53 | 1 | $add->('/foo/bar/baz/Base.mc'); | |||||||||
| 54 | 1 | $self->interp->_flush_load_cache(); | |||||||||
| 55 | |||||||||||
| 56 | 1 | $check_parent->( '/Base.mc', $base_class ); | |||||||||
| 57 | 1 | $check_parent->( '/foo/Base.mc', '/Base.mc' ); | |||||||||
| 58 | 1 | $check_parent->( '/foo/bar/baz/Base.mc', '/foo/Base.mc' ); | |||||||||
| 59 | 1 | $check_parent->( '/comp.mc', '/Base.mc' ); | |||||||||
| 60 | |||||||||||
| 61 | 1 | $check_parent->( '/foo/comp.mc', '/foo/Base.mc' ); | |||||||||
| 62 | 1 | $check_parent->( '/foo/bar/comp.mc', '/foo/Base.mc' ); | |||||||||
| 63 | 1 | $check_parent->( '/foo/bar/baz/comp.mc', '/foo/bar/baz/Base.mc' ); | |||||||||
| 64 | |||||||||||
| 65 | 1 | $add->( '/foo/bar/baz/none.mc', "undef" ); | |||||||||
| 66 | 1 | $check_parent->( '/foo/bar/baz/none.mc', $base_class ); | |||||||||
| 67 | |||||||||||
| 68 | 1 | $add->( '/foo/bar/baz/top.mc', "'/Base.mc'" ); | |||||||||
| 69 | 1 | $check_parent->( '/foo/bar/baz/top.mc', '/Base.mc' ); | |||||||||
| 70 | |||||||||||
| 71 | 1 | $add->( '/foo/bar/baz/top2.mc', "'../../Base.mc'" ); | |||||||||
| 72 | 1 | $check_parent->( '/foo/bar/baz/top2.mc', '/foo/Base.mc' ); | |||||||||
| 73 | |||||||||||
| 74 | # Multiple autobases same directory | ||||||||||
| 75 | 1 | $add->('/Base.mp'); | |||||||||
| 76 | 1 | $add->('/foo/Base.mp'); | |||||||||
| 77 | 1 | $self->interp->_flush_load_cache(); | |||||||||
| 78 | 1 | $check_parent->( '/Base.mp', $base_class ); | |||||||||
| 79 | 1 | $check_parent->( '/Base.mc', '/Base.mp' ); | |||||||||
| 80 | 1 | $check_parent->( '/foo/Base.mp', '/Base.mc' ); | |||||||||
| 81 | 1 | $check_parent->( '/foo/Base.mc', '/foo/Base.mp' ); | |||||||||
| 82 | 1 | $check_parent->( '/foo/comp.mc', '/foo/Base.mc' ); | |||||||||
| 83 | |||||||||||
| 84 | # Remove most autobases, test parents again | ||||||||||
| 85 | # | ||||||||||
| 86 | 1 | $remove->('/Base.mp'); | |||||||||
| 87 | 1 | $remove->('/Base.mc'); | |||||||||
| 88 | 1 | $remove->('/foo/Base.mp'); | |||||||||
| 89 | 1 | $remove->('/foo/Base.mc'); | |||||||||
| 90 | 1 | $self->interp->_flush_load_cache(); | |||||||||
| 91 | |||||||||||
| 92 | 1 | $check_parent->( '/comp.mc', $base_class ); | |||||||||
| 93 | 1 | $check_parent->( '/foo/comp.mc', $base_class ); | |||||||||
| 94 | 1 | $check_parent->( '/foo/bar/comp.mc', $base_class ); | |||||||||
| 95 | 1 | $check_parent->( '/foo/bar/baz/comp.mc', '/foo/bar/baz/Base.mc' ); | |||||||||
| 96 | 1 | $check_parent->( '/foo/bar/baz/Base.mc', $base_class ); | |||||||||
| 97 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 98 | |||||||||||
| 99 | 1 | ▶ | sub test_cycles : Tests { | ||||||||
|
Subroutine
test_cycles: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 100 | 1 | my $self = shift; | |||||||||
| 101 | |||||||||||
| 102 | # An inheritance cycle | ||||||||||
| 103 | # | ||||||||||
| 104 | 1 | $self->add_comp( | |||||||||
| 105 | path => '/cycle/Base.mc', | ||||||||||
| 106 | src => "<%flags>\nextends => '/cycle/c/index.mc'\n</%flags>\n", | ||||||||||
| 107 | ); | ||||||||||
| 108 | 1 | $self->test_comp( | |||||||||
| 109 | path => '/cycle/c/index.mc', | ||||||||||
| 110 | src => "ok", | ||||||||||
| 111 | expect_error => qr/inheritance cycle/, | ||||||||||
| 112 | ); | ||||||||||
| 113 | |||||||||||
| 114 | # This isn't a cycle but a bug that tried to preload default parent was causing | ||||||||||
| 115 | # it to infinite loop | ||||||||||
| 116 | # | ||||||||||
| 117 | 1 | $self->add_comp( | |||||||||
| 118 | path => '/pseudo/Base.mc', | ||||||||||
| 119 | src => "<%flags>\nextends => '/pseudo/c/index.mc'\n</%flags>\n", | ||||||||||
| 120 | ); | ||||||||||
| 121 | 1 | $self->test_comp( | |||||||||
| 122 | path => '/pseudo/c/index.mc', | ||||||||||
| 123 | src => "<%flags>\nextends => undef\n</%flags>\nok", | ||||||||||
| 124 | expect => 'ok', | ||||||||||
| 125 | ); | ||||||||||
| 126 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 127 | |||||||||||
| 128 | 1 | ▶ | sub test_wrapping : Tests { | ||||||||
|
Subroutine
test_wrapping: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 129 | 1 | my $self = shift; | |||||||||
| 130 | |||||||||||
| 131 | 1 | $self->add_comp( | |||||||||
| 132 | path => '/wrap/Base.mc', | ||||||||||
| 133 | src => ' | ||||||||||
| 134 | <%augment wrap> | ||||||||||
| 135 | <html> | ||||||||||
| 136 | % inner(); | ||||||||||
| 137 | </html> | ||||||||||
| 138 | </%augment> | ||||||||||
| 139 | ' | ||||||||||
| 140 | ); | ||||||||||
| 141 | 1 | $self->add_comp( | |||||||||
| 142 | path => '/wrap/subdir/Base.mc', | ||||||||||
| 143 | src => ' | ||||||||||
| 144 | |||||||||||
| 145 | <%method hello> | ||||||||||
| 146 | Hello world | ||||||||||
| 147 | </%method> | ||||||||||
| 148 | |||||||||||
| 149 | ' | ||||||||||
| 150 | ); | ||||||||||
| 151 | 1 | $self->add_comp( | |||||||||
| 152 | path => '/wrap/subdir/subdir2/Base.mc', | ||||||||||
| 153 | src => ' | ||||||||||
| 154 | <%augment wrap> | ||||||||||
| 155 | <body> | ||||||||||
| 156 | % inner(); | ||||||||||
| 157 | </body> | ||||||||||
| 158 | </%augment> | ||||||||||
| 159 | ' | ||||||||||
| 160 | ); | ||||||||||
| 161 | 1 | $self->test_comp( | |||||||||
| 162 | path => '/wrap/subdir/subdir2/wrap_me.mc', | ||||||||||
| 163 | src => '<% $self->hello %>', | ||||||||||
| 164 | expect => ' | ||||||||||
| 165 | <html> | ||||||||||
| 166 | |||||||||||
| 167 | <body> | ||||||||||
| 168 | |||||||||||
| 169 | Hello world | ||||||||||
| 170 | </body> | ||||||||||
| 171 | </html> | ||||||||||
| 172 | ' | ||||||||||
| 173 | ); | ||||||||||
| 174 | 1 | $self->test_comp( | |||||||||
| 175 | path => '/wrap/subdir/subdir2/dont_wrap_me.mc', | ||||||||||
| 176 | src => ' | ||||||||||
| 177 | <%class>method wrap { $.main() }</%class> | ||||||||||
| 178 | <% $self->hello() %> | ||||||||||
| 179 | ', | ||||||||||
| 180 | expect => 'Hello world' | ||||||||||
| 181 | ); | ||||||||||
| 182 | 1 | $self->test_comp( | |||||||||
| 183 | path => '/wrap/subdir/subdir2/dont_wrap_me_either.mc', | ||||||||||
| 184 | src => ' | ||||||||||
| 185 | <%class>CLASS->no_wrap;</%class> | ||||||||||
| 186 | <% $self->hello() %> | ||||||||||
| 187 | ', | ||||||||||
| 188 | expect => 'Hello world' | ||||||||||
| 189 | ); | ||||||||||
| 190 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 191 | |||||||||||
| 192 | # not yet implemented | ||||||||||
| 193 | 0 | ▶ | sub _test_no_main_in_autobase { | ||||||||
|
Subroutine
_test_no_main_in_autobase: not called CC=1 SCAR=6.9
| |||||||||||
| 194 | 0 | my $self = shift; | |||||||||
| 195 | |||||||||||
| 196 | 0 | $self->test_comp( | |||||||||
| 197 | path => '/wrap/Base.mc', | ||||||||||
| 198 | src => ' | ||||||||||
| 199 | <body> | ||||||||||
| 200 | % inner(); | ||||||||||
| 201 | </body> | ||||||||||
| 202 | ', | ||||||||||
| 203 | expect_error => qr/content found in main body of autobase/, | ||||||||||
| 204 | ); | ||||||||||
| 205 | } | ||||||||||
| 206 | |||||||||||
| 207 | 1 | ▶ | sub test_recompute_inherit : Tests { | ||||||||
|
Subroutine
test_recompute_inherit: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 208 | 1 | my $self = shift; | |||||||||
| 209 | 1 | my $interp = $self->interp; | |||||||||
| 210 | |||||||||||
| 211 | # Test that /comp.mc class can be recomputed without garbage collection issues. | ||||||||||
| 212 | # | ||||||||||
| 213 | 0 | ▶ | my $remove = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 214 | 0 | my ($path) = @_; | |||||||||
| 215 | |||||||||||
| 216 | 0 | $self->remove_comp( path => $path, ); | |||||||||
| 217 | 1 | }; | |||||||||
| 218 | |||||||||||
| 219 | 1 | $self->add_comp( path => '/comp.mc', src => ' ' ); | |||||||||
| 220 | 1 | $self->interp->load('/comp.mc'); | |||||||||
| 221 | 1 | $self->add_comp( path => '/Base.mc', src => ' ' ); | |||||||||
| 222 | 1 | $self->interp->_flush_load_cache(); | |||||||||
| 223 | 1 | $self->interp->load('/comp.mc'); | |||||||||
| 224 | 1 | ok(1); | |||||||||
| 225 | |||||||||||
| 226 | 1 | return; | |||||||||
| 227 | 1 | ▶ | } | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 228 | |||||||||||
| 229 | 1 | 1; | |||||||||