File Coverage

blib/lib/Mason/t/StaticSource.pm
Criterion Covered Total %
statement 58 58 100.0
branch n/a
condition n/a
subroutine 14 14 100.0
pod 0 7 0.0
total 72 79 91.1


line stmt bran cond sub pod time code
1             package Mason::t::StaticSource;
2             $Mason::t::StaticSource::VERSION = '2.23';
3 1     1   761 use Test::Class::Most parent => 'Mason::Test::Class';
  1         27369  
  1         6  
4 1     1   68 use Mason::Util qw(write_file touch_file);
  1         2  
  1         88  
5              
6             sub setup : Test(setup) {
7 4     4 0 1182 my ($self) = @_;
8              
9 4         28 $self->setup_dirs();
10 4         103 $self->add_comp(
11             path => "/ss/remove_component.mc",
12             src => "I will be removed.\n",
13             );
14 4         14 $self->add_comp(
15             path => "/ss/change_component.mc",
16             src => "I will be changed.\n",
17             );
18 1     1   5 }
  1         2  
  1         3  
19              
20             sub write_comp {
21 2     2 0 10 my ( $self, $path, $contents ) = @_;
22 2         20 my $source_file = $self->interp->load($path)->cmeta->source_file;
23 2         18 write_file( $source_file, $contents );
24             }
25              
26             sub remove_comp {
27 2     2 0 6 my ( $self, $path ) = @_;
28 2         13 my $source_file = $self->interp->load($path)->cmeta->source_file;
29 2         273 unlink($source_file);
30             }
31              
32             sub test_change_no_ss : Tests {
33 1     1 0 151 my $self = shift;
34 1         7 $self->test_comp(
35             src => '<& /ss/change_component.mc &>',
36             expect => 'I will be changed.',
37             );
38 1         1000177 sleep(1); # Make sure timestamp changes
39 1         28 $self->write_comp( "/ss/change_component.mc", "I have changed!\n" );
40 1         10 $self->test_comp(
41             src => '<& /ss/change_component.mc &>',
42             expect => 'I have changed!',
43             );
44 1     1   341 }
  1         2  
  1         4  
45              
46             sub test_change_and_touch_ss : Tests {
47 1     1 0 688 my $self = shift;
48 1         7 my $touch_file = $self->temp_dir . "/purge.dat";
49 1         6 $self->setup_interp( static_source => 1, static_source_touch_file => $touch_file );
50 1         24 $self->test_comp(
51             src => '<& /ss/change_component.mc &>',
52             expect => 'I will be changed.',
53             );
54 1         1000091 sleep(1); # Make sure timestamp changes
55 1         19 $self->interp->load('/ss/change_component.mc');
56 1         18 $self->write_comp( "/ss/change_component.mc", "I have changed!\n" );
57 1         8 $self->test_comp(
58             src => '<& /ss/change_component.mc &>',
59             expect => 'I will be changed.',
60             );
61 1         6 touch_file($touch_file);
62 1         5 $self->test_comp(
63             src => '<& /ss/change_component.mc &>',
64             expect => 'I have changed!',
65             );
66 1     1   303 }
  1         3  
  1         6  
67              
68             sub test_remove_no_ss : Tests {
69 1     1 0 215 my $self = shift;
70 1         7 $self->test_comp(
71             src => '<& /ss/remove_component.mc &>',
72             expect => 'I will be removed.',
73             );
74 1         5 $self->remove_comp("/ss/remove_component.mc");
75 1         10 $self->test_comp(
76             src => '<& /ss/remove_component.mc &>',
77             expect_error => qr/could not find component/
78             );
79 1     1   247 }
  1         1  
  1         3  
80              
81             sub test_remove_and_touch_ss : Tests {
82 1     1 0 165 my $self = shift;
83 1         7 my $touch_file = $self->temp_dir . "/purge.dat";
84 1         4 $self->setup_interp( static_source => 1, static_source_touch_file => $touch_file );
85 1         23 $self->test_comp(
86             src => '<& /ss/remove_component.mc &>',
87             expect => 'I will be removed.',
88             );
89 1         8 $self->remove_comp("/ss/remove_component.mc");
90 1         6 $self->test_comp(
91             src => '<& /ss/remove_component.mc &>',
92             expect => 'I will be removed.',
93             );
94 1         5 touch_file($touch_file);
95 1         9 $self->test_comp(
96             src => '<& /ss/remove_component.mc &>',
97             expect_error => qr/could not find component/
98             );
99 1     1   260 }
  1         2  
  1         3  
100              
101             1;