line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catalyst::Plugin::Widget; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Catalyst::Plugin::Widget - Simple way to create reusable HTML fragments |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
=head1 VERSION |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
Version 0.04 |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
14
|
|
|
|
|
|
|
|
15
|
2
|
|
|
2
|
|
32236
|
use strict; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
88
|
|
16
|
2
|
|
|
2
|
|
11
|
use warnings qw(all); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
614
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 DESCRIPTION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Termin I<widget> means kind of object that knows about current L<Catalyst> |
22
|
|
|
|
|
|
|
context and can be easily stringified to text representation. |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
A typical example of a widget - L<CatalystX::Widget::Paginator> module. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 SYNOPSIS |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Setup plugin: |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
use Catalyst( qw( Widget ) ); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Create custom widget class: |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
package MyApp::Widget::Greeting; |
37
|
|
|
|
|
|
|
use Moose; |
38
|
|
|
|
|
|
|
extends 'Catalyst::Plugin::Widget::Base'; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has nobody => ( is => 'rw', default => "Sorry, what's your name?" ); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub render { |
43
|
|
|
|
|
|
|
my $self = shift; |
44
|
|
|
|
|
|
|
$self->context->can('user_exists') && $self->context->user_exists ? |
45
|
|
|
|
|
|
|
'Hello, ' . $self->context->user->name : $self->nobody; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
1; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Create widget instance in controller>: |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub index :Path :Args(0) { |
54
|
|
|
|
|
|
|
my ( $self,$c ) = @_; |
55
|
|
|
|
|
|
|
my $w = $c->widget('~Greeting'); |
56
|
|
|
|
|
|
|
$c->stash( greet => $w ); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Place widget onto template: |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
From auth: [% greet %] |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 METHODS |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=head2 widget |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Create instance of widget class. |
71
|
|
|
|
|
|
|
Class name is handled by the following rules: |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
- starting with the '+': use the entire name (except '+' sign) |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
- starting with the '~': use name (except '~' sign) prepended with |
76
|
|
|
|
|
|
|
application class name and '::Widget::'. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
- other: use name prepended with application config parameter |
79
|
|
|
|
|
|
|
$config->{ widget }{ default_namespace } or string 'CatalystX::Widget::' |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Examples: |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
$c->widget('+Some::Class'); # Some::Class |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
$c->widget('~Class'); # App::Widget::Class |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
$c->widget('Class'); # CatalystX::Widget::Class |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
App->config{ widget }{ default_namespace } = 'Local'; |
90
|
|
|
|
|
|
|
$c->widget('Class'); # Local::Class |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub widget { |
95
|
0
|
|
|
0
|
1
|
|
my ( $app,$class ) = splice @_,0,2; |
96
|
|
|
|
|
|
|
|
97
|
0
|
0
|
|
|
|
|
unless ( $class =~ s/^\+// ) { |
98
|
|
|
|
|
|
|
$class = ( $class =~ s/^~// ? |
99
|
|
|
|
|
|
|
ref( $app ) . '::Widget::' : |
100
|
|
|
|
|
|
|
$app->config->{ widget }{ default_namespace } || |
101
|
0
|
0
|
0
|
|
|
|
'CatalystX::Widget::' ) . $class; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
|
104
|
0
|
0
|
|
|
|
|
eval 'use ' . $class unless $app->{ __widgets__ }{ $class }; |
105
|
0
|
0
|
|
|
|
|
return $app->error( "Can't create widget: " . $@ ) if $@; |
106
|
0
|
|
0
|
|
|
|
$app->{ __widgets__ }{ $class } ||= 1; |
107
|
|
|
|
|
|
|
|
108
|
0
|
0
|
|
|
|
|
$app->log->debug( 'Creating widget: "' . $class . '"' ) |
109
|
|
|
|
|
|
|
if $app->debug; |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
return $class->new( $app, @_ ); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=head1 AUTHOR |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Oleg A. Mamontov, C<< <oleg at mamontov.net> >> |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head1 BUGS |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Please report any bugs or feature requests to C<bug-catalyst-plugin-widget at rt.cpan.org>, or through |
123
|
|
|
|
|
|
|
the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-Plugin-Widget>. I will be notified, and then you'll |
124
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=head1 SUPPORT |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
perldoc Catalyst::Plugin::Widget |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
You can also look for information at: |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=over 4 |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-Plugin-Widget> |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
L<http://annocpan.org/dist/Catalyst-Plugin-Widget> |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=item * CPAN Ratings |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
L<http://cpanratings.perl.org/d/Catalyst-Plugin-Widget> |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=item * Search CPAN |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
L<http://search.cpan.org/dist/Catalyst-Plugin-Widget/> |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=back |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Copyright 2010 Oleg A. Mamontov. |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
162
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
163
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
1; |
172
|
|
|
|
|
|
|
|