| 1 | package Mason::Plugin::Cache::t::Basic; | ||
| 2 | 1 | ▶ | BEGIN { |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 3 | 1 | $Mason::Plugin::Cache::t::Basic::VERSION = '0.05'; | |
| 4 | } | ||
| 5 | 1 | ▶ | use Test::Class::Most parent => 'Mason::Test::Class'; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | 1 | __PACKAGE__->default_plugins( [ '@Default', 'Cache' ] ); | |
| 8 | |||
| 9 | 1 | ▶ | sub test_cache_defaults : Tests { |
|
Subroutine
test_cache_defaults: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 10 | 1 | my $self = shift; | |
| 11 | $self->run_test_in_comp( | ||
| 12 | path => '/cache/defaults.mc', | ||
| 13 | 1 | ▶ | test => sub { |
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||
| 14 | 1 | my $comp = shift; | |
| 15 | 1 | foreach my $cache ( $comp->cache, $comp->m->cache ) { | |
| 16 | 2 | is( $cache->label, 'File', 'cache->label' ); | |
| 17 | 2 | is( $cache->namespace, $comp->cmeta->path, 'cache->namespace' ); | |
| 18 | } | ||
| 19 | } | ||
| 20 | 1 | ); | |
| 21 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 22 | |||
| 23 | 1 | ▶ | sub test_cache_method : Tests { |
|
Subroutine
test_cache_method: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 24 | 1 | my $self = shift; | |
| 25 | 1 | $self->test_comp( | |
| 26 | path => '/cache.mc', | ||
| 27 | src => ' | ||
| 28 | <%shared> | ||
| 29 | $.count => 0 | ||
| 30 | </%shared> | ||
| 31 | |||
| 32 | <%method getset ($key)> | ||
| 33 | <%perl>$.count($.count+1);</%perl> | ||
| 34 | <% $.cache->compute($key, sub { $key . $.count }) %> | ||
| 35 | </%method> | ||
| 36 | |||
| 37 | namespace: <% $m->cache->namespace %> | ||
| 38 | <% $.getset("foo") %> | ||
| 39 | <% $.getset("bar") %> | ||
| 40 | <% $.getset("bar") %> | ||
| 41 | <% $.getset("foo") %> | ||
| 42 | ', | ||
| 43 | expect => ' | ||
| 44 | namespace: /cache.mc | ||
| 45 | foo1 | ||
| 46 | |||
| 47 | bar2 | ||
| 48 | |||
| 49 | bar2 | ||
| 50 | |||
| 51 | foo1 | ||
| 52 | ', | ||
| 53 | ); | ||
| 54 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 55 | |||
| 56 | 1 | ▶ | sub test_cache_filter : Tests { |
|
Subroutine
test_cache_filter: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 57 | 1 | my $self = shift; | |
| 58 | |||
| 59 | 1 | $self->test_comp( | |
| 60 | src => ' | ||
| 61 | % my $i = 1; | ||
| 62 | % foreach my $key (qw(foo bar)) { | ||
| 63 | % $.Repeat(3), $.Cache($key) {{ | ||
| 64 | i = <% $i++ %> | ||
| 65 | % }} | ||
| 66 | % } | ||
| 67 | ', | ||
| 68 | expect => ' | ||
| 69 | i = 1 | ||
| 70 | i = 1 | ||
| 71 | i = 1 | ||
| 72 | i = 2 | ||
| 73 | i = 2 | ||
| 74 | i = 2 | ||
| 75 | ', | ||
| 76 | ); | ||
| 77 | |||
| 78 | 1 | $self->test_comp( | |
| 79 | src => ' | ||
| 80 | % my $i = 1; | ||
| 81 | % foreach my $key (qw(foo foo)) { | ||
| 82 | % $.Cache($key), $.Repeat(3) {{ | ||
| 83 | i = <% $i++ %> | ||
| 84 | % }} | ||
| 85 | % } | ||
| 86 | ', | ||
| 87 | expect => ' | ||
| 88 | i = 1 | ||
| 89 | i = 2 | ||
| 90 | i = 3 | ||
| 91 | i = 1 | ||
| 92 | i = 2 | ||
| 93 | i = 3 | ||
| 94 | ' | ||
| 95 | ); | ||
| 96 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 97 | |||
| 98 | 1 | ▶ | sub test_cache_with_defer : Tests { |
|
Subroutine
test_cache_with_defer: called CC=1 SCAR=5.1
Pod
undocumented
| |||
| 99 | 1 | return "not yet implemented"; | |
| 100 | |||
| 101 | 0 | my $self = shift; | |
| 102 | |||
| 103 | 0 | my $path = '/cache/defer.mc'; | |
| 104 | 0 | $self->add_comp( | |
| 105 | path => $path, | ||
| 106 | src => ' | ||
| 107 | % $.Cache("all") {{ | ||
| 108 | foo = <% $m->defer(sub { $Foo::foo }) %> | ||
| 109 | % $Foo::foo++; | ||
| 110 | % }} | ||
| 111 | ' | ||
| 112 | ); | ||
| 113 | 0 | $Foo::foo = 5; | |
| 114 | 0 | $self->test_existing_comp( path => $path, expect => 'foo = 6' ); | |
| 115 | 0 | $Foo::foo = 10; | |
| 116 | 0 | $self->test_existing_comp( path => $path, expect => 'foo = 6' ); | |
| 117 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 118 | |||
| 119 | 1 | ▶ | sub test_cache_memoization : Tests { |
|
Subroutine
test_cache_memoization: called CC=1 SCAR=0.0
Pod
undocumented
| |||
| 120 | 1 | my $self = shift; | |
| 121 | $self->run_test_in_comp( | ||
| 122 | path => '/cache/memoize.mc', | ||
| 123 | 1 | ▶ | test => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 124 | 1 | my $comp = shift; | |
| 125 | |||
| 126 | 1 | is( $comp->cache_memoized, undef, 'Cache not memoized by default' ); | |
| 127 | 1 | $comp->cache_memoized('buu!'); | |
| 128 | 1 | is( $comp->cache_memoized, 'buu!', 'Memoization updated' ); | |
| 129 | } | ||
| 130 | 1 | ); | |
| 131 | |||
| 132 | $self->run_test_in_comp( | ||
| 133 | path => '/cache/memoize.mc', | ||
| 134 | 1 | ▶ | test => sub { |
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||
| 135 | 1 | my $comp = shift; | |
| 136 | |||
| 137 | 1 | is( $comp->cache_memoized, 'buu!', 'Cache memoization works across requests' ); | |
| 138 | } | ||
| 139 | 1 | ); | |
| 140 | 1 | ▶ | } |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||