| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package MasonX::StaticBuilder::Component; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
744
|
use strict; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
42
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
48
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use base qw(Class::Accessor); |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
915
|
|
|
7
|
|
|
|
|
|
|
MasonX::StaticBuilder::Component->mk_accessors(qw(comp_root comp_name)); |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Carp; |
|
10
|
|
|
|
|
|
|
use File::Spec; |
|
11
|
|
|
|
|
|
|
use HTML::Mason; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
MasonX::StaticBuilder::Component -- fill in a single template file |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $tmpl = MasonX::StaticBuilder::Component->new($file); |
|
20
|
|
|
|
|
|
|
my $output = $tmpl->fill_in(%args); |
|
21
|
|
|
|
|
|
|
print $output; |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head2 new() |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
Constructor. Give it a hashref containing the following args: |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=over 4 |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=item * |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
comp_root |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=item * |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
comp_name |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=back |
|
40
|
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=begin testing |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
use_ok('MasonX::StaticBuilder::Component'); |
|
44
|
|
|
|
|
|
|
my $t = MasonX::StaticBuilder::Component->new({ |
|
45
|
|
|
|
|
|
|
comp_root => "t", |
|
46
|
|
|
|
|
|
|
comp_name => "/test-component" |
|
47
|
|
|
|
|
|
|
}); |
|
48
|
|
|
|
|
|
|
isa_ok($t, 'MasonX::StaticBuilder::Component'); |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
can_ok($t, qw(comp_root comp_name)); |
|
51
|
|
|
|
|
|
|
like($t->comp_root(), qr!/t$!, "comp_root()"); |
|
52
|
|
|
|
|
|
|
is($t->comp_name(), "/test-component", "comp_name()"); |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
my $no = MasonX::StaticBuilder::Component->new({ |
|
55
|
|
|
|
|
|
|
comp_root => "t", |
|
56
|
|
|
|
|
|
|
comp_name => "/this/file/does/not/exist", |
|
57
|
|
|
|
|
|
|
}); |
|
58
|
|
|
|
|
|
|
is($no, undef, "new returns undef if the file can't be loaded"); |
|
59
|
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=end testing |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub new { |
|
65
|
|
|
|
|
|
|
my ($class, $args) = @_; |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $comp_root = File::Spec->rel2abs($args->{comp_root}); |
|
68
|
|
|
|
|
|
|
my $comp_name = $args->{comp_name}; |
|
69
|
|
|
|
|
|
|
my $filename = $comp_root . $comp_name; |
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
if ($filename && -e $filename && -T $filename) { |
|
72
|
|
|
|
|
|
|
my $self = {}; |
|
73
|
|
|
|
|
|
|
bless $self, $class; |
|
74
|
|
|
|
|
|
|
$self->comp_root($comp_root); |
|
75
|
|
|
|
|
|
|
$self->comp_name($comp_name); |
|
76
|
|
|
|
|
|
|
return $self; |
|
77
|
|
|
|
|
|
|
} else { |
|
78
|
|
|
|
|
|
|
return undef; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
} |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head2 fill_in() |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Fill in the template, by running all the mason code in the template |
|
85
|
|
|
|
|
|
|
files. Any parameters passed to this method will be available to the |
|
86
|
|
|
|
|
|
|
template as named args. |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
For example: |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
$tmpl->fill_in( foo => "bar"); |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
And in the template: |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
<%args> |
|
95
|
|
|
|
|
|
|
$foo => undef |
|
96
|
|
|
|
|
|
|
%args> |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
Foo is <% $foo %> |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=begin testing |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my $t = MasonX::StaticBuilder::Component->new({ |
|
103
|
|
|
|
|
|
|
comp_root => "t", |
|
104
|
|
|
|
|
|
|
comp_name => "/test-component" |
|
105
|
|
|
|
|
|
|
}); |
|
106
|
|
|
|
|
|
|
my $out = $t->fill_in( foo => "bar" ); |
|
107
|
|
|
|
|
|
|
like($out, qr/This is a test/, "template handles simple text"); |
|
108
|
|
|
|
|
|
|
like($out, qr/42/, "template handles mason directives"); |
|
109
|
|
|
|
|
|
|
like($out, qr/foo is bar/, "template handles args"); |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
=end testing |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub fill_in { |
|
116
|
|
|
|
|
|
|
my ($self, @args) = @_; |
|
117
|
|
|
|
|
|
|
my $output; |
|
118
|
|
|
|
|
|
|
my $interp = HTML::Mason::Interp->new( |
|
119
|
|
|
|
|
|
|
comp_root => $self->comp_root(), |
|
120
|
|
|
|
|
|
|
out_method => \$output |
|
121
|
|
|
|
|
|
|
); |
|
122
|
|
|
|
|
|
|
$interp->exec($self->comp_name(), @args); |
|
123
|
|
|
|
|
|
|
return $output; |
|
124
|
|
|
|
|
|
|
} |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
1; |