line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Maypole::View::Mason; |
2
|
1
|
|
|
1
|
|
1028
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
47
|
|
3
|
1
|
|
|
1
|
|
6
|
use base 'Maypole::View::Base'; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
1939
|
|
4
|
|
|
|
|
|
|
use HTML::Mason; |
5
|
|
|
|
|
|
|
use Maypole::Constants; |
6
|
|
|
|
|
|
|
use Data::Dumper; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.3'; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
{ |
11
|
|
|
|
|
|
|
package HTML::Mason::Commands; |
12
|
|
|
|
|
|
|
use vars qw/$request $config $classmetadata $objects $base/; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub template { |
16
|
|
|
|
|
|
|
my ($self, $r) = @_; |
17
|
|
|
|
|
|
|
my $class = ref $r; |
18
|
|
|
|
|
|
|
my $label = "path0"; |
19
|
|
|
|
|
|
|
my $output; |
20
|
|
|
|
|
|
|
my %args=$self->vars($r); |
21
|
|
|
|
|
|
|
my $mason = HTML::Mason::Interp->new( |
22
|
|
|
|
|
|
|
comp_root => [ map { [ $label++ => $_ ] } grep {$_} $self->paths($r) ], |
23
|
|
|
|
|
|
|
out_method => \$output, |
24
|
|
|
|
|
|
|
error_mode => "fatal" |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
no strict 'refs'; |
27
|
|
|
|
|
|
|
map {${"HTML::Mason::Commands::".$_} =$args{$_} } keys %args; |
28
|
|
|
|
|
|
|
my ($comp) = "/".$r->template; |
29
|
|
|
|
|
|
|
if (! $mason->comp_exists($comp) ) { |
30
|
|
|
|
|
|
|
$r->{error} = "Could not find $comp"; |
31
|
|
|
|
|
|
|
return ERROR; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
eval { |
34
|
|
|
|
|
|
|
$mason->exec( $comp , %{$r->params}); |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
if ($@) { |
37
|
|
|
|
|
|
|
$r->{error} = $@; |
38
|
|
|
|
|
|
|
return ERROR; |
39
|
|
|
|
|
|
|
} else { |
40
|
|
|
|
|
|
|
$r->{output} = $output; |
41
|
|
|
|
|
|
|
return OK; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
1; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 NAME |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Maypole::View::Mason - A HTML::Mason view class for Maypole |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head1 SYNOPSIS |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
BeerDB->config->{view} = "Maypole::View::Mason"; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
And then: |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
<%args> |
58
|
|
|
|
|
|
|
@breweries |
59
|
|
|
|
|
|
|
%args> |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
% for my $brewery (@breweries) { |
62
|
|
|
|
|
|
|
... |
63
|
|
|
|
|
|
|
| <% $brewery->name %> |
64
|
|
|
|
|
|
|
% } |
65
|
|
|
|
|
|
|
... |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 DESCRIPTION |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
This class allows you to use C components for your Maypole |
70
|
|
|
|
|
|
|
templates. It provides precisely the same path searching and template |
71
|
|
|
|
|
|
|
variables as the Template Toolkit view class, although you will need |
72
|
|
|
|
|
|
|
to produce your own set of templates as the factory-supplied templates |
73
|
|
|
|
|
|
|
are, of course, Template Toolkit ones. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Please see the Maypole manual, and in particular, the C chapter, |
76
|
|
|
|
|
|
|
for the template variables available and for a refresher on how template |
77
|
|
|
|
|
|
|
components are resolved. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 template |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
This is the main method of this module. See L. |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 SEE ALSO |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
L,L |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=head1 AUTHOR |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Simon Cozens |
91
|
|
|
|
|
|
|
Marcus Ramberg |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 THANKS |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This module was made possible thanks to a Perl Foundation grant. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |