| 1 | package Mason::t::Reload; | ||
| 2 | 1 | $Mason::t::Reload::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_reload : Tests { |
|
Subroutine
test_reload: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 6 | 1 | my $self = shift; | |
| 7 | 1 | my $class; | |
| 8 | |||
| 9 | 1 | $self->add_comp( | |
| 10 | path => "/reload.mc", | ||
| 11 | src => <<'EOF', | ||
| 12 | <%class> | ||
| 13 | sub foo { 'foo' } | ||
| 14 | sub baz { 'baz1' } | ||
| 15 | </%class> | ||
| 16 | Foo | ||
| 17 | EOF | ||
| 18 | ); | ||
| 19 | 1 | is( $self->interp->run("/reload")->output, "Foo\n", "before reload" ); | |
| 20 | 1 | $class = $self->interp->load("/reload.mc"); | |
| 21 | 1 | is( $class->foo(), 'foo', "method foo" ); | |
| 22 | 1 | is( $class->baz(), 'baz1', "method baz" ); | |
| 23 | 1 | ok( $class->can('foo'), "can call foo before reload" ); | |
| 24 | 1 | ok( !$class->can('bar'), "cannot call bar before reload" ); | |
| 25 | 1 | ok( $class->can('baz'), "can call baz before reload" ); | |
| 26 | |||
| 27 | 1 | sleep(1); # so timestamp will be different | |
| 28 | |||
| 29 | 1 | $self->add_comp( | |
| 30 | path => "/reload.mc", | ||
| 31 | src => <<'EOF', | ||
| 32 | <%class> | ||
| 33 | sub bar { 'bar' } | ||
| 34 | sub baz { 'baz2' } | ||
| 35 | </%class> | ||
| 36 | Bar | ||
| 37 | EOF | ||
| 38 | ); | ||
| 39 | 1 | is( $self->interp->run("/reload")->output, "Bar\n", "after reload" ); | |
| 40 | 1 | is( $class->bar(), 'bar', "method bar" ); | |
| 41 | 1 | is( $class->baz(), 'baz2', "method baz" ); | |
| 42 | 1 | ok( $class->can('bar'), "can call bar after reload" ); | |
| 43 | 1 | ok( !$class->can('foo'), "cannot call foo after reload" ); | |
| 44 | 1 | ok( $class->can('baz'), "can call baz after reload" ); | |
| 45 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 46 | |||
| 47 | 1 | ▶ | sub test_reload_parent : Tests { |
|
Subroutine
test_reload_parent: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 48 | 1 | my $self = shift; | |
| 49 | 1 | my $interp = $self->interp; | |
| 50 | |||
| 51 | 1 | $self->add_comp( path => '/foo/bar/baz.mc', src => '<% $.num1 %> <% $.num2 %>' ); | |
| 52 | 1 | $self->add_comp( path => '/foo/Base.mc', src => '<%class>method num1 { 5 }</%class>' ); | |
| 53 | 1 | $self->add_comp( path => '/Base.mc', src => '<%class>method num2 { 6 }</%class>' ); | |
| 54 | |||
| 55 | 1 | $self->test_existing_comp( path => '/foo/bar/baz.mc', expect => '5 6' ); | |
| 56 | |||
| 57 | 1 | $self->interp->_flush_load_cache(); | |
| 58 | 1 | sleep(1); | |
| 59 | |||
| 60 | 1 | $self->add_comp( path => '/foo/Base.mc', src => "<%class>method num1 { 7 }</%class>" ); | |
| 61 | 1 | $self->add_comp( path => '/Base.mc', src => "<%class>method num2 { 8 }</%class>" ); | |
| 62 | 1 | $self->test_existing_comp( path => '/foo/bar/baz.mc', expect => '7 8' ); | |
| 63 | |||
| 64 | 1 | $self->interp->_flush_load_cache(); | |
| 65 | 1 | sleep(1); | |
| 66 | |||
| 67 | 1 | $self->add_comp( | |
| 68 | path => '/Base.mc', | ||
| 69 | src => "<%class>method num1 { 10 }\nmethod num2 { 11 }\n</%class>" | ||
| 70 | ); | ||
| 71 | 1 | $self->test_existing_comp( path => '/foo/bar/baz.mc', expect => '7 11' ); | |
| 72 | |||
| 73 | 1 | $self->interp->_flush_load_cache(); | |
| 74 | 1 | sleep(1); | |
| 75 | |||
| 76 | 1 | $self->remove_comp( path => '/foo/Base.mc' ); | |
| 77 | 1 | $self->test_existing_comp( path => '/foo/bar/baz.mc', expect => '10 11' ); | |
| 78 | |||
| 79 | 1 | $self->interp->_flush_load_cache(); | |
| 80 | 1 | sleep(1); | |
| 81 | |||
| 82 | 1 | $self->remove_comp( path => '/foo/Base.mc' ); | |
| 83 | 1 | $self->add_comp( path => '/foo/bar/baz.mc', src => 'hi' ); | |
| 84 | 1 | $self->add_comp( path => '/Base.mp', src => 'method wrap { print "wrap1" }' ); | |
| 85 | 1 | $self->test_existing_comp( path => '/foo/bar/baz.mc', expect => 'wrap1' ); | |
| 86 | |||
| 87 | 1 | $self->interp->_flush_load_cache(); | |
| 88 | 1 | sleep(1); | |
| 89 | |||
| 90 | 1 | $self->add_comp( path => '/Base.mp', src => 'method wrap { print "wrap2" }' ); | |
| 91 | 1 | $self->test_existing_comp( path => '/foo/bar/baz.mc', expect => 'wrap2' ); | |
| 92 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 93 | |||
| 94 | 1 | ▶ | sub test_no_unnecessary_reload : Tests { |
|
Subroutine
test_no_unnecessary_reload: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 95 | 1 | my $self = shift; | |
| 96 | 1 | my $interp = $self->interp; | |
| 97 | |||
| 98 | 1 | $self->add_comp( path => '/foo.mc', src => ' ' ); | |
| 99 | 1 | my $id1 = $interp->load('/foo.mc')->cmeta->id; | |
| 100 | 1 | $self->interp->_flush_load_cache(); | |
| 101 | 1 | my $id2 = $interp->load('/foo.mc')->cmeta->id; | |
| 102 | 1 | ok( $id1 == $id2 ); | |
| 103 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 104 | |||
| 105 | 1 | 1; | |