-
Notifications
You must be signed in to change notification settings - Fork 3
/
README
220 lines (169 loc) · 7.05 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
-+m
.%- ..
[ Squatting ] . m*#-+
A Camping-inspired Web Microframework for Perl m+*##+m.
...- m#*#%-..
--.. +mm###-+-.
..- m..*#####*m++
.--+.-m#m+.%+-m###+
.-m..###+...% m#m-##% .
+%+.. -++.+ m--#-+
.. --..%*-%- --+#.m
- - -.--+# .. +#m+
..#-+%. +.#..
. . . .%#-... .-+.-
. -.+m+-. .. .-.++#.*-... . .
..- .+. ..+..+---+%---.--.--#m#+.. +
.-. m .. -.m++m####%###-##%.++*%++ m .
. +. m-- *##*#+###..-m+m.++.#-####-%-m. ..
-m#--%###-m+- --+%m..--. - .-*%####% ..-. -.
-...-*##%m+.+-+.++-m#+-. .. . +.+%%-#m..m#%m+..-.
-..*#**m.-.+..-.m+-##+.- +m-+*%- %-- %##-
...++*++.. . . +m##*-. -.%m+ + -.-++%+-
. ++###.%.-- . . *m+##%%. .-%-#- . ...#...
..%*+m . + m+####%.. .-+%#+- .-#--
-.#mm.. --.- +%#-m#%% ...%+##%+ .+..\-
.+mm%+ .. ..m-m.+%%+m**+.. --.##%m--. + #-.
.--%%. . m .#++ %-- +mm-. ...m##m-.+ -+*--
+-#+- . .##+.. +..m .m-#%#%-- -.##-.
.%.**+. ...m#%..- .. ...# m . +-%#.%+ . %#%..+
-+##%.+.. #-. -. .m+..m -#%mm .--**++
.-%.*m+-...mm+ . .+ +- -m-+. ..*#.. .
.-+*m#%m**++-+ .. -##.%%.- - ..##+-.
- +-*%##%+mm--+ . .#m-m- - -+.m.##-+.
.. m*##*#*%-m+- - . . .m.+.m .. m%+.*-% -
...+##m%####m-+m- -. .. ..- ++.. . +.. +%-###m-%.
..%#-%#++%####.+.m-+. . +m#+#+%.. . -#*###m.--
. %-mm ++-mm+**##%mm. - .+mm#+*.+--.#/##-+-+m .
..+.# - +-. m%m#m#*+.-..+##*###%m#%#% .--- - . .
.-m#m. . . ..m+...#%m--+-*#+######.%+.. .+
..m-#%. . ..- .+-- - .---.-**-+--...
.+.#m#m- .. . . - -..- ..*
. +-##-+. . -- . ..
.+##m%+
.%.---
.. .
...
http://en.wikipedia.org/wiki/Squatting
https://github.com/beppu/squatting
The API (should fit comfortably in your head with plenty of room to spare).
---------------------------------------------------------------------------
## [0] BEGINNING AN APP
package App;
use Squatting; # <-- This use statement is where the magic happens.
#
# %App::CONFIG
# &App::D
# &App::Controllers::R
# @App::Controllers::C
# %App::Controllers::C
# &App::Controllers::C
# &App::Views::R
# @App::Views::V
# %App::Views::V
#
# @App::ISA = qw(Squatting);
# # ...and Squatting->isa('Class::C3::Componentised')
## [1] CUSTOMIZING AN APP
our %CONFIG = (
# App configuration goes in a hash.
);
# Code that needs to run when the app starts goes in init().
sub init {
my ($class) = @_;
$class->next::method();
}
# Code that needs to run on every request goes in service().
sub service {
my ($class, $controller, @args) = @_;
# before controller
my $content = $class->next::method($controller, @args);
# after controller
return $content;
}
1;
## [2] DEFINE CONTROLLERS
package App::Controllers;
our @C = (
C(
'Home' => [ '/' ],
get => sub {
}
),
C(
'Post' => [ '/(\d+)/(\d+)/(\w+)' ],
get => sub {
my ($self, $year, $month, $slug) = @_;
},
post => sub {
my ($self, $year, $month, $slug) = @_;
}
)
C(
'Comment' => [ '/comment' ],
post => sub {
}
)
);
1;
## [3] DEFINE VIEWS
package App::Views;
our @V = (
V(
'Default',
layout => sub {
my ($self, $v, $content) = @_;
# This optional method allows you to wrap the content
# that your template methods return.
return "HEADER $content FOOTER";
},
_partial => sub {
my ($self, $v) = @_;
# If you want a view to not be wrapped by the layout,
# its name should begin with "_".
return "exactly what you want";
},
wrapped => sub {
my ($self, $v) = @_;
# This template's name does not begin with "_" so it
# WILL be wrapped by the layout.
return "wrapped content";
}
_ => sub {
my ($self, $v) = @_;
# If a named template method is not found, this method
# will be run. Think of it as AUTOLOAD for views.
return "something";
},
),
);
1;
SUMMARY OF THE SQUATTING API
----------------------------
%App::CONFIG Where your app configuration is expected to be
&App::init Code that runs on applicationn initialization
&App::service Code that runs on every HTTP request
App::Controllers Package where controllers are expected to be
@App::Controllers::C Array where controllers are expected to be
&App::Controllers::C Helper function for creating Squatting::Controller
objects
&App::Controllers::R Helper function for generating URL paths;
Think "R" for "route".
App::Views Package where views are expected to be
@App::Views::V Array where views are expected to be
&App::Views::V Helper function for creating Squatting::View objects
&App::Views::R Helper function for generating URL paths;
It's the exact same function as &App::Controllers::R.
&App::Controllers::R == &App::Views::R
You should be able to memorize this quite easily, and I hope you
never have to use a search engine to figure out how any of this works.
The entire API should fit comfortably inside your mind with plenty of
room to spare.
For more information:
`perldoc Squatting`
`perldoc Squatting::Controller`
`perldoc Squatting::View`
For practical examples, see:
Rhetoric (a simple blogging system)
Pod::Server (a POD browser)
Stardust (a COMET server)