line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::Widget::ThroughView; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Catalyst::Plugin::Widget::ThroughView - Widget rendered through L<Catalyst::View> |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=cut |
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
3798
|
use Carp qw( croak ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
69
|
|
10
|
1
|
|
|
1
|
|
540
|
use Moose::Role; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
requires 'context'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package MyApp::Widget::Sample; |
18
|
|
|
|
|
|
|
use Moose; |
19
|
|
|
|
|
|
|
extends 'Catalyst::Plugin::Widget::Base'; |
20
|
|
|
|
|
|
|
with 'Catalyst::Plugin::Widget::ThroughView'; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has '+view' => ( is => 'rw', default => 'MyView' ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
1; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 METHODS |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 extension |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
Returns default extension for template file name. Defaults to assume '.tt' |
32
|
|
|
|
|
|
|
for view inherited from L<Catalyst::View::TT>, '.tx' for |
33
|
|
|
|
|
|
|
L<Catalyst::View::Xslate> descendants and '' for remainders. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=cut |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has extension => ( is => 'rw', isa => 'Str', lazy => 1, |
38
|
|
|
|
|
|
|
builder => '_extension' ); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# builder for 'extension'. |
41
|
|
|
|
|
|
|
sub _extension { |
42
|
|
|
|
|
|
|
my ( $self ) = @_; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
$self->view_instance->isa('Catalyst::View::TT') && |
45
|
|
|
|
|
|
|
'.tt' || |
46
|
|
|
|
|
|
|
$self->view_instance->isa('Catalyst::View::Xslate') && |
47
|
|
|
|
|
|
|
'.tx' || |
48
|
|
|
|
|
|
|
''; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 populate_stash |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Fill stash with required data. Can be altered in descendants with L<Moose> |
55
|
|
|
|
|
|
|
method modifiers. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=cut |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub populate_stash { |
60
|
|
|
|
|
|
|
my $self = shift; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
$self->context->stash( self => $self ); |
63
|
|
|
|
|
|
|
$self->context->stash( template => $self->template ) |
64
|
|
|
|
|
|
|
if $self->template; |
65
|
|
|
|
|
|
|
} |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 render |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Overriden method from L<Catalyst::Plugin::Widget::Base>. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub render { |
75
|
|
|
|
|
|
|
my ( $self ) = @_; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# we have to modify Moose internal storage |
78
|
|
|
|
|
|
|
local $self->context->{ stash } = {}; |
79
|
|
|
|
|
|
|
local $self->context->res->{ body }; |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
$self->populate_stash; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# rendering |
84
|
|
|
|
|
|
|
$self->context->forward( $self->view_instance ); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
return $self->context->res->body; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head2 template |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Returns name of template file using for widget rendering. |
93
|
|
|
|
|
|
|
Default is lower cased widget class name remaining (after word 'Widget') |
94
|
|
|
|
|
|
|
with all '::' replaced with '/' and 'extension' appended. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=cut |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
has template => ( is => 'rw', isa => 'Str | Undef', lazy => 1, |
99
|
|
|
|
|
|
|
builder => '_template' ); |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# builder for 'template'. |
102
|
|
|
|
|
|
|
sub _template { |
103
|
|
|
|
|
|
|
my ( $self ) = @_; |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
( my $t = ref $self ) =~ s/.*::(Widget::.+)/$1/; |
106
|
|
|
|
|
|
|
$t =~ s|::|/|g; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
return lc($t) . $self->extension; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 view |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
Returns L<Catalyst::View> (name or instance) for widget rendering. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=cut |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
has view => ( is => 'rw', isa => 'Catalyst::View | Str', required => 1 ); |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head2 view_instance |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Returns L<Catalyst::View> instance for widget rendering. |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=cut |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
has view_instance => ( is => 'rw', isa => 'Catalyst::View', init_arg => undef, |
128
|
|
|
|
|
|
|
lazy => 1, builder => '_view_instance' ); |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
# builder for 'view_instance'. |
131
|
|
|
|
|
|
|
sub _view_instance { |
132
|
|
|
|
|
|
|
my $self = shift; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
ref $self->view ? |
135
|
|
|
|
|
|
|
$self->view : |
136
|
|
|
|
|
|
|
$self->context->view( $self->view ) or |
137
|
|
|
|
|
|
|
croak "No such view: '" . $self->view ."'"; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |
142
|
|
|
|
|
|
|
|