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