line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package SweetPea::Application; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
82946
|
use warnings; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
90
|
|
4
|
2
|
|
|
2
|
|
13
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
432
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
BEGIN { |
7
|
2
|
|
|
2
|
|
14
|
use Exporter(); |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
71
|
|
8
|
2
|
|
|
2
|
|
12
|
use vars qw( @ISA @EXPORT @EXPORT_OK ); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
186
|
|
9
|
2
|
|
|
2
|
|
39
|
@ISA = qw( Exporter ); |
10
|
2
|
|
|
|
|
121
|
@EXPORT = qw(sweet); |
11
|
|
|
|
|
|
|
} |
12
|
|
|
|
|
|
|
|
13
|
2
|
|
|
2
|
|
13
|
use base 'SweetPea'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
89610
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 NAME |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
SweetPea::Application - A full stack web framework for the rest of us. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
=head1 VERSION |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Version 0.025 |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=cut |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $VERSION = '0.025'; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 SYNOPSIS |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
SweetPea::Application is a full-stack web application framework built atop |
30
|
|
|
|
|
|
|
of the L web framework. SweetPea::Application aims to provide all |
31
|
|
|
|
|
|
|
the functionality common to building complete and robust web applications |
32
|
|
|
|
|
|
|
via a suite of packages through a unified API. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# build a full-stack web application (from the cli) |
35
|
|
|
|
|
|
|
sweetpea make -f |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
use SweetPea; |
38
|
|
|
|
|
|
|
sweet->routes({ |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
'/' => sub { |
41
|
|
|
|
|
|
|
shift->forward('/way'); |
42
|
|
|
|
|
|
|
}, |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
'/way' => sub { |
45
|
|
|
|
|
|
|
shift->html('I am the way the truth and the light!'); |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
})->run; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
To Get Started, Review |
51
|
|
|
|
|
|
|
L or L. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=cut |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub sweet { |
56
|
0
|
|
|
0
|
1
|
|
return SweetPea::Application->new; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub _plugins { |
60
|
0
|
|
|
0
|
|
|
my $self = shift; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# use existing |
63
|
0
|
|
|
|
|
|
SweetPea::_plugins($self); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
# configuration support |
66
|
|
|
|
|
|
|
$self->plug( |
67
|
|
|
|
|
|
|
'config', |
68
|
|
|
|
|
|
|
sub { |
69
|
0
|
|
|
0
|
|
|
require 'SweetPea/Application/Config.pm'; |
70
|
0
|
|
|
|
|
|
my $self = shift; |
71
|
0
|
|
|
|
|
|
return SweetPea::Application::Config->new($self); |
72
|
|
|
|
|
|
|
} |
73
|
0
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# template support |
76
|
|
|
|
|
|
|
$self->plug( |
77
|
|
|
|
|
|
|
'template', |
78
|
|
|
|
|
|
|
sub { |
79
|
0
|
|
|
0
|
|
|
require 'SweetPea/Application/Template.pm'; |
80
|
0
|
|
|
|
|
|
my $self = shift; |
81
|
0
|
|
|
|
|
|
return SweetPea::Application::Template->new($self); |
82
|
|
|
|
|
|
|
} |
83
|
0
|
|
|
|
|
|
); |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# database support |
86
|
|
|
|
|
|
|
$self->plug( |
87
|
|
|
|
|
|
|
'data', |
88
|
|
|
|
|
|
|
sub { |
89
|
0
|
|
|
0
|
|
|
require 'SweetPea/Application/Data.pm'; |
90
|
0
|
|
|
|
|
|
my $self = shift; |
91
|
0
|
|
|
|
|
|
return SweetPea::Application::Data->new($self); |
92
|
|
|
|
|
|
|
} |
93
|
0
|
|
|
|
|
|
); |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# object mapping support |
96
|
|
|
|
|
|
|
$self->plug( |
97
|
|
|
|
|
|
|
'dbo', |
98
|
|
|
|
|
|
|
sub { |
99
|
0
|
|
|
0
|
|
|
require 'SweetPea/Application/Orm.pm'; |
100
|
0
|
|
|
|
|
|
my $self = shift; |
101
|
0
|
|
|
|
|
|
return SweetPea::Application::Orm->new($self); |
102
|
|
|
|
|
|
|
} |
103
|
0
|
|
|
|
|
|
); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# localization support |
106
|
|
|
|
|
|
|
$self->plug( |
107
|
|
|
|
|
|
|
'locale', |
108
|
|
|
|
|
|
|
sub { |
109
|
0
|
|
|
0
|
|
|
require 'SweetPea/Application/Locale.pm'; |
110
|
0
|
|
|
|
|
|
my $self = shift; |
111
|
0
|
|
|
|
|
|
return SweetPea::Application::Locale->new($self); |
112
|
|
|
|
|
|
|
} |
113
|
0
|
|
|
|
|
|
); |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# role-based access control support |
116
|
|
|
|
|
|
|
$self->plug( |
117
|
|
|
|
|
|
|
'rbac', |
118
|
|
|
|
|
|
|
sub { |
119
|
0
|
|
|
0
|
|
|
require 'SweetPea/Application/Rbac.pm'; |
120
|
0
|
|
|
|
|
|
my $self = shift; |
121
|
0
|
|
|
|
|
|
return SweetPea::Application::Rbac->new($self); |
122
|
|
|
|
|
|
|
} |
123
|
0
|
|
|
|
|
|
); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# email support |
126
|
|
|
|
|
|
|
$self->plug( |
127
|
|
|
|
|
|
|
'email', |
128
|
|
|
|
|
|
|
sub { |
129
|
0
|
|
|
0
|
|
|
require 'SweetPea/Application/Email.pm'; |
130
|
0
|
|
|
|
|
|
my $self = shift; |
131
|
0
|
|
|
|
|
|
return SweetPea::Application::Email->new($self); |
132
|
|
|
|
|
|
|
} |
133
|
0
|
|
|
|
|
|
); |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
# input validation support |
136
|
|
|
|
|
|
|
$self->plug( |
137
|
|
|
|
|
|
|
'validate', |
138
|
|
|
|
|
|
|
sub { |
139
|
0
|
|
|
0
|
|
|
require 'SweetPea/Application/Validate.pm'; |
140
|
0
|
|
|
|
|
|
my $self = shift; |
141
|
0
|
|
|
|
|
|
return SweetPea::Application::Validate->new($self); |
142
|
|
|
|
|
|
|
} |
143
|
0
|
|
|
|
|
|
); |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# model accessor |
146
|
|
|
|
|
|
|
$self->plug( |
147
|
|
|
|
|
|
|
'model', |
148
|
|
|
|
|
|
|
sub { |
149
|
0
|
|
|
0
|
|
|
require 'SweetPea/Application/Model.pm'; |
150
|
0
|
|
|
|
|
|
my $self = shift; |
151
|
0
|
|
|
|
|
|
return SweetPea::Application::Model->new($self, @_); |
152
|
|
|
|
|
|
|
} |
153
|
0
|
|
|
|
|
|
); |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
# view accessor |
156
|
|
|
|
|
|
|
$self->plug( |
157
|
|
|
|
|
|
|
'view', |
158
|
|
|
|
|
|
|
sub { |
159
|
0
|
|
|
0
|
|
|
require 'SweetPea/Application/View.pm'; |
160
|
0
|
|
|
|
|
|
my $self = shift; |
161
|
0
|
|
|
|
|
|
return SweetPea::Application::View->new($self, @_); |
162
|
|
|
|
|
|
|
} |
163
|
0
|
|
|
|
|
|
); |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
# html elements builder |
166
|
|
|
|
|
|
|
$self->plug( |
167
|
|
|
|
|
|
|
'builder', |
168
|
|
|
|
|
|
|
sub { |
169
|
0
|
|
|
0
|
|
|
require 'SweetPea/Application/Builder.pm'; |
170
|
0
|
|
|
|
|
|
my $self = shift; |
171
|
0
|
|
|
|
|
|
return SweetPea::Application::Builder->new($self); |
172
|
|
|
|
|
|
|
} |
173
|
0
|
|
|
|
|
|
); |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
# load non-core plugins from App.pm |
176
|
0
|
0
|
|
|
|
|
if (-e "sweet/App.pm") { |
177
|
0
|
|
|
|
|
|
eval 'require q(App.pm)'; |
178
|
0
|
0
|
|
|
|
|
if ($@) { |
179
|
0
|
|
|
|
|
|
warn $@; |
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
else { |
182
|
0
|
|
|
|
|
|
eval { App->plugins($self) }; |
|
0
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
0
|
|
|
|
|
|
return $self; |
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
sub finish { |
190
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
# return captured data for mock transactions |
193
|
0
|
0
|
|
|
|
|
if ($self->{store}->{application}->{mock_run}) { |
194
|
0
|
0
|
|
|
|
|
if ($self->{store}->{template}) { |
|
|
0
|
|
|
|
|
|
195
|
0
|
0
|
|
|
|
|
if (length($self->{store}->{template}->{data}) > 1) { |
196
|
0
|
|
|
|
|
|
$self->html($self->{store}->{template}->{data}); |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
} |
199
|
|
|
|
|
|
|
# check for laziness |
200
|
|
|
|
|
|
|
elsif (length($self->template->{data}) > 1) { |
201
|
0
|
|
|
|
|
|
$self->html($self->template->{data}); |
202
|
|
|
|
|
|
|
} |
203
|
0
|
|
|
|
|
|
$self->session->flush(); |
204
|
0
|
|
|
|
|
|
return 1; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
# check if template data exists |
208
|
0
|
0
|
|
|
|
|
if (length($self->{store}->{template}->{data}) > 1) { |
|
|
0
|
|
|
|
|
|
209
|
0
|
|
|
|
|
|
print $self->{store}->{template}->{data}; |
210
|
|
|
|
|
|
|
} |
211
|
|
|
|
|
|
|
# check for laziness |
212
|
|
|
|
|
|
|
elsif (length($self->template->{data}) > 1) { |
213
|
0
|
|
|
|
|
|
print $self->template->{data}; |
214
|
|
|
|
|
|
|
} |
215
|
|
|
|
|
|
|
# print gathered html |
216
|
|
|
|
|
|
|
else { |
217
|
0
|
|
|
|
|
|
foreach ( @{ $self->html } ) { |
|
0
|
|
|
|
|
|
|
218
|
0
|
|
|
|
|
|
print "$_\n"; |
219
|
|
|
|
|
|
|
} |
220
|
|
|
|
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
|
|
|
|
# commit session changes if a session has been created |
223
|
0
|
|
|
|
|
|
$self->session->flush(); |
224
|
|
|
|
|
|
|
} |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=head1 AUTHOR |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
Al Newkirk, C<< >> |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
=head1 BUGS |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
233
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
234
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
=head1 SUPPORT |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
perldoc SweetPea::Application |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
You can also look for information at: |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=over 4 |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
L |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
L |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=item * CPAN Ratings |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
L |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
=item * Search CPAN |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
L |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=back |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
Copyright 2009 Al Newkirk. |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
271
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
272
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
|
277
|
|
|
|
|
|
|
=cut |
278
|
|
|
|
|
|
|
|
279
|
|
|
|
|
|
|
1; # End of SweetPea::Application |