Articulate.pm

filter: Statementstmt 80.4% 33 / 41 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 76.9% 10 / 13 Podpod 100% 1 / 1 totaltotal 80.0% 44 / 55 CC 4 SCAR 6.9
CC
4
Cov
80%
enable
6.0
__ANON__
2.0
__ANON__
2.0
CRAP 2.0
« Articulate/TestEnv.pm ↑ Summary Articulate/Role/Flow.pm »
1 package Articulate;
2 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 5 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 5 with 'MooX::Singleton';
7  
8 5 ▶use Articulate::Service;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 5 ▶use Module::Load ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 5 our $VERSION = '0.004';
11  
12 =head1 NAME
13  
14 Articulate - A lightweight Perl CMS Framework
15  
16 =head1 WARNING
17  
18 This is very much in alpha. Things will change. Feel free to build
19 things and have fun, but don't hook up anything business-critical just
20 yet!
21  
22 =head1 SYNOPSIS
23  
24 # (in bin/app.pl)
25 use Dancer;
26 use Dancer::Plugin::Articulate;
27 articulate_app->enable;
28 dance;
29  
30 B<Articulate> provides a content management service for your web app.
31 It's lightweight, i.e. it places minimal demands on your app while
32 maximising 'whipuptitude': it gives you a single interface in code to a
33 framework that's totally modular underneath, and it won't claim any URL
34 endpoints for itself.
35  
36 You don't need to redesign your app around Articulate, it's a service
37 that you call on when you need it, and all the 'moving parts' can be
38 switched out if you want to do things your way.
39  
40 It's written in Perl, the fast, reliable 'glue language' that's perfect
41 for agile web development projects, and currently runs on the L<Dancer>
42 and L<Dancer2> web frameworks.
43  
44 =head1 GETTING STARTED
45  
46 Don't forget to install Articulate - remember, it's a library, not an
47 app.
48  
49 # From source:
50 perl Makefile.PL
51 make
52 make test
53 make install
54  
55 Check out the examples in the C<examples> folder of the distribution.
56  
57 To add Articulate to your own app, you'll need to:
58  
59 =over
60  
61 =item * add it to your C<bin/app.pl> or similar (see example above) using either L<Dancer::Plugin::Articulate> or L<Dancer2::Plugin::Articulate>.
62  
63 =item * edit your C<config.yml> to configure the components you want (check each of the components for a description of their config options - or just borrow a config from one of the examples)
64  
65 =item * write any custom code you want if you don't like what's there, and just swap it out in the config.
66  
67 =item * polish off your front-end, all the backend is taken care of!
68  
69 =back
70  
71 Curious about how it all fits together? Read on...
72  
73 =head1 DESCRIPTION
74  
75 Articulate is a set of components that work together to provide a
76 content management service that will sit alongside an existing Dancer
77 app or form the basis of a new one.
78  
79 If you want to see one in action, grab the source and run:
80  
81 # If you have Dancer and Dancer::Plugin::Articulate installed:
82 cd examples/plain-speaking
83 perl bin/app.pl -e dancer1
84  
85 # Or, if you have Dancer2 and Dancer2::Plugin::Articulate installed:
86 cd examples/plain-speaking
87 perl bin/app.psgi
88  
89 You can see how it's configured by looking at
90  
91 examples/plain-speaking/config.yml
92  
93 Notice that C<bin/app.pl> doesn't directly load anything but the
94 Articulate plugin (which loads config into this module). Everything you
95 need is in C<config.yml>, and you can replace components with ones
96 you've written if your app needs to do different things.
97  
98 =head2 Request/Response lifecycle summary
99  
100 In a B<route>, you parse user input and pick the parameters you want to
101 send to the B<service>. Have a look at
102 L<Articulate::Routes::Transparent> for some examples. The intention is
103 that routes are as 'thin' as possible: business logic should all be
104 done by some part of the service and not in the route handler. The
105 route handler maps endpoints (URLs) to service requests; structured
106 responses are passed back as return values and are picked up by the
107 B<serialiser>.
108  
109 B<Routes> pass B<requests> to B<services>. A B<request> contains a
110 B<verb> (like C<create>) and B<data> (like the B<location> you want to
111 create it at and the B<content> you want to place there). See
112 L<Articulate::Request> for more details.
113  
114 The B<service> is responsible for handling requests for managed
115 content. L<Articulate::Service> B<delegates> to a service B<provider>,
116 asking each in turn if they are willing to handle the request (normally
117 the provider will dertermine this based on the request verb). A
118 provider typically checks a user has suitable permission, then
119 interacts with the content storage system.
120  
121 B<Storage> is controlled by L<Articulate::Storage>. It delegates to a
122 storage class which is configured for actions like C<get_item> and
123 C<set_meta>.
124  
125 Content is stored in a structure called an B<item> (see
126 L<Articulate::Item>), which has a C<location> (see
127 L<Articulate::Location>), the B<content> (which could be a binary blob
128 like an image, plain text, markdown, XML, etc.) and the associated
129 B<metadata> or B<meta> (which is a hashref).
130  
131 Before items can be placed in storage, the service should take care to
132 run them through B<validation>. L<Articulate::Validation> delegates
133 this to validators, and if there are any applicable validators, they
134 will check if the content is valid. The content may also be
135 B<enriched>, i.e. further metadata added, like the time at which the
136 request was made (consult L<Articulate::Enrichment> for details).
137  
138 After items are retrieved from storage, there is the opportunity to
139 B<augment> them, for instance by including relevant content from
140 elsewhere which belongs in the response. See
141 L<Articulate::Augmentation> for details on this.
142  
143 If at any time uncaught errors are thrown, including recognised
144 L<Articulate::Error> objects, they are caught and handled by
145 L<Articulate::Service>. L<Articulate::Service> should therefore always
146 return an L<Articulate::Response> object.
147  
148 Once the request finds it back to the Route it will typically be
149 B<serialised> immediately (see L<Articulate::Serialiser>), and the
150 resulting response passed back to the user.
151  
152 =head2 Components
153  
154 The following classes are persistent, configurable B<components> of the
155 system:
156  
157 =over
158  
159 =item * L<Articulate::Augmentation>
160  
161 =item * L<Articulate::Authentication>
162  
163 =item * L<Articulate::Caching>
164  
165 =item * L<Articulate::Construction>
166  
167 =item * L<Articulate::Enrichment>
168  
169 =item * L<Articulate::FrameworkAdapter>
170  
171 =item * L<Articulate::Navigation>
172  
173 =item * L<Articulate::Serialisation>
174  
175 =item * L<Articulate::Service>
176  
177 =item * L<Articulate::Storage>
178  
179 =item * L<Articulate::Validation>
180  
181 =back
182  
183 =head2 Data Classes
184  
185 The following classes are used for passing request data between
186 components:
187  
188 =over
189  
190 =item * L<Articulate::Credentials>
191  
192 =item * L<Articulate::Error>
193  
194 =item * L<Articulate::File>
195  
196 =item * L<Articulate::Item>
197  
198 =item * L<Articulate::Location>
199  
200 =item * L<Articulate::LocationSpecification>
201  
202 =item * L<Articulate::Permission>
203  
204 =item * L<Articulate::Request>
205  
206 =item * L<Articulate::Response>
207  
208 =back
209  
210 =head2 Other modules of interest
211  
212 =over
213  
214 =item * L<Articulate::Syntax>
215  
216 =item * L<Articulate::Syntax::Routes>
217  
218 =item * L<Articulate::Role::Component>
219  
220 =item * L<Articulate::Role::Routes>
221  
222 =item * L<Articulate::Role::Service>
223  
224 =item * L<Articulate::Role::Storage>
225  
226 =back
227  
228 =head2 Instantiation
229  
230 Articulate provides a very handy way of creating (or B<instantiating>)
231 objects through your config. The following config, for instance,
232 assignes to the providers attribute (on some other object), an arrayref
233 of four objects, the first created without no arguments, two created
234 with arguments, and a final one created without arguments but using an
235 unusual constructor.
236  
237 providers:
238 - MyProvider::Simple
239 - class: MyProvider::Congfigurable
240 args:
241 verbose: 1
242 - MyProvider::Congfigurable:
243 lax: 1
244 verbose: 1
245 - class: MyProvider::Idiosyncratic
246 constuctor: tada
247  
248 For more details, see L<Articulate::Syntax>.
249  
250 =head2 Delegation
251  
252 A key part of the flexibility of Articulate is that objects often
253 B<delegate> functions to other objects (the B<providers>)
254  
255 Typically, one class delegates to a series of providers, which are each
256 passed the same arguments in turn. L<Articulate::Augmentation> is a
257 good example of this. Sometimes the response from one provider will
258 halt the delegation - see L<Articulate::Authorisation> for an example
259 of this.
260  
261 Occasionally, only one provider is possible, for instance
262 L<Articulate::FrameworkAdapter>. In this case there is a substitution
263 rather than a delegation.
264  
265 =cut
266  
267 =head1 METHOD
268  
269 =head3 enable
270  
271 Sets up the routes. This does not happen at construction so you can
272 control the point at which routes are declared.
273  
274 =head1 ATTRIBUTES
275  
276 =head3 enabled
277  
278 Please do not set this directly, use C<enable> instead.
279  
280 =head3 routes
281  
282 The packages which provide routes for Articulate. See
283 L<Articulate::Syntax::Routes> and L<Articulate::Role::Routes> for more
284 details.
285  
286 =head3 components
287  
288 The different working pieces of the Articulate app. Components all have
289 access to each other indirectly and they provide features across
290 Articulate; see L<Articulate::Role::Component> for more details.
291  
292 =cut
293  
294 sub enable {
295 0 ▶ my $self = shift;
Subroutine enable: not called CC=2 SCAR=17.9
Pod documented
296 0 foreach my $route ( @{ $self->routes } ) {
297 0 $route->app($self);
298 0 $route->enable;
299 }
300 0 $self->enabled(1);
301 }
302  
303 has enabled => (
304 is => 'rw',
305 4 ▶ default => sub { 0 }
Subroutine __ANON__: called CC=1 SCAR=0.0
306 5 );
307  
308 has routes => (
309 is => 'rw',
310 0 ▶ default => sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
311 coerce => sub {
312 4 ▶ Module::Load::load('Articulate::Syntax');
Subroutine __ANON__: called CC=1 SCAR=0.0
313 4 Articulate::Syntax::instantiate_array(@_);
314 },
315 trigger => sub {
316 4 ▶ my $self = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
317 4 my $orig = shift;
318 4 $_->app($self) foreach @$orig;
319 },
320 5 );
321  
322 has components => (
323 is => 'rw',
324 0 ▶ default => sub { {} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
325 coerce => sub {
326 4 ▶ my $orig = shift;
Subroutine __ANON__: called CC=1 SCAR=0.0
327 4 Module::Load::load('Articulate::Syntax');
328 4 Articulate::Syntax::instantiate_selection($orig);
329  
330 },
331 trigger => sub {
332 4 ▶ my $self = shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
333 4 my $orig = shift;
334 4 $orig->{$_}->app($self) foreach keys %$orig;
335 },
336 5 );
337  
338 =head1 BUGS
339  
340 Bugs should be reported to the L<github issue
341 tracker|https://github.com/pdl/Articulate/issues>. Pull Requests
342 welcome!
343  
344 =head1 COPYRIGHT
345  
346 Articulate is Copyright 2014-2015 Daniel Perrett. You are free to use
347 it subject to the same terms as perl: see the LICENSE file included in
348 this distribution for what this means.
349  
350 Currently Articulate is bundled with versions of other software whose
351 license information you can access from the LICENSE file.
352  
353 =cut
354  
355 5 1;
« Articulate/TestEnv.pm ↑ Summary Articulate/Role/Flow.pm »