File Coverage

blib/lib/Stencil/Source/Awncorp/Class.pm
Criterion Covered Total %
statement 11 11 100.0
branch n/a
condition n/a
subroutine 4 4 100.0
pod n/a
total 15 15 100.0


line stmt bran cond sub pod time code
1             package Stencil::Source::Awncorp::Class;
2              
3 2     2   60964 use 5.014;
  2         8  
4              
5 2     2   11 use strict;
  2         5  
  2         43  
6 2     2   11 use warnings;
  2         4  
  2         79  
7              
8 2     2   1394 use Data::Object::Class;
  2         2097  
  2         22  
9              
10             extends 'Stencil::Source';
11              
12             our $VERSION = '0.01'; # VERSION
13              
14             1;
15              
16              
17              
18             =encoding utf8
19              
20             =head1 NAME
21              
22             Stencil::Source::Awncorp::Class
23              
24             =cut
25              
26             =head1 ABSTRACT
27              
28             Stencil Generator for Classes
29              
30             =cut
31              
32             =head1 SYNOPSIS
33              
34             use Stencil::Source::Awncorp::Class;
35              
36             my $s = Stencil::Source::Awncorp::Class->new;
37              
38             =cut
39              
40             =head1 DESCRIPTION
41              
42             This package provides a L<Stencil> generator for L<Data::Object::Class> based
43             roles and L<Test::Auto> tests. This generator produces the following specification:
44              
45             name: MyApp
46             desc: Doing One Thing Very Well
47              
48             libraries:
49             - MyApp::Types
50              
51             inherits:
52             - MyApp::Parent
53              
54             integrates:
55             - MyApp::Role::Doable
56              
57             attributes:
58             - is: ro
59             name: name
60             type: Str
61             form: req
62              
63             operations:
64             - from: class
65             make: lib/MyApp.pm
66             - from: class-test
67             make: t/MyApp.t
68              
69             scenarios:
70             - name: exports
71             desc: exporting the following functions
72              
73             functions:
74             - name: handler_a
75             args: "(Str $key) : Any"
76             desc: executes something which triggers something else
77              
78             methods:
79             - name: handle_b
80             args: "(Str $key) : Any"
81             desc: executes something which triggers something else
82              
83             routines:
84             - name: handle_c
85             args: "(Str $key) : Any"
86             desc: executes something which triggers something else
87              
88             =cut
89              
90             =head1 INHERITS
91              
92             This package inherits behaviors from:
93              
94             L<Stencil::Source>
95              
96             =cut
97              
98             =head1 LIBRARIES
99              
100             This package uses type constraints from:
101              
102             L<Types::Standard>
103              
104             =cut
105              
106             =head1 AUTHOR
107              
108             Al Newkirk, C<awncorp@cpan.org>
109              
110             =head1 LICENSE
111              
112             Copyright (C) 2011-2019, Al Newkirk, et al.
113              
114             This is free software; you can redistribute it and/or modify it under the terms
115             of the The Apache License, Version 2.0, as elucidated in the L<"license
116             file"|https://github.com/iamalnewkirk/stencil-source-awncorp/blob/master/LICENSE>.
117              
118             =head1 PROJECT
119              
120             L<Wiki|https://github.com/iamalnewkirk/stencil-source-awncorp/wiki>
121              
122             L<Project|https://github.com/iamalnewkirk/stencil-source-awncorp>
123              
124             L<Initiatives|https://github.com/iamalnewkirk/stencil-source-awncorp/projects>
125              
126             L<Milestones|https://github.com/iamalnewkirk/stencil-source-awncorp/milestones>
127              
128             L<Contributing|https://github.com/iamalnewkirk/stencil-source-awncorp/blob/master/CONTRIBUTE.md>
129              
130             L<Issues|https://github.com/iamalnewkirk/stencil-source-awncorp/issues>
131              
132             =cut
133              
134             __DATA__
135              
136             @=spec
137              
138             name: MyApp
139             desc: Doing One Thing Very Well
140              
141             libraries:
142             - MyApp::Types
143              
144             inherits:
145             - MyApp::Parent
146              
147             integrates:
148             - MyApp::Role::Doable
149              
150             attributes:
151             - is: ro
152             name: name
153             type: Str
154             form: req
155              
156             operations:
157             - from: class
158             make: lib/MyApp.pm
159             - from: class-test
160             make: t/MyApp.t
161              
162             scenarios:
163             - name: exports
164             desc: exporting the following functions
165              
166             functions:
167             - name: handler_a
168             args: "(Str $key) : Any"
169             desc: executes something which triggers something else
170              
171             methods:
172             - name: handle_b
173             args: "(Str $key) : Any"
174             desc: executes something which triggers something else
175              
176             routines:
177             - name: handle_c
178             args: "(Str $key) : Any"
179             desc: executes something which triggers something else
180              
181             @=class
182              
183             package [% data.name %];
184              
185             use 5.014;
186              
187             use strict;
188             use warnings;
189              
190             use registry;
191             use routines;
192              
193             use Data::Object::Class;
194             use Data::Object::ClassHas;
195              
196             [%- IF data.inherits %]
197             [%- FOR item IN data.inherits %]
198             extends '[% item %]';
199             [%- END %]
200             [% END -%]
201              
202             [%- IF data.integrates %]
203             [%- FOR item IN data.integrates %]
204             with '[% item %]';
205             [%- END %]
206             [% END -%]
207              
208             # VERSION
209              
210             [%- IF data.attributes %]
211             # ATTRIBUTES
212             [% FOR item IN data.attributes %]
213             has '[% item.name %]' => (
214             is => '[% item.is %]',
215             isa => '[% item.type %]',
216             [% item.form %] => 1,
217             );
218             [% END -%]
219             [% END -%]
220              
221             [%- IF data.functions %]
222             # FUNCTIONS
223             [% FOR item IN data.functions %]
224             fun [% item.name %]() {
225             # do something ...
226              
227             return;
228             }
229             [% END -%]
230             [% END -%]
231              
232             [%- IF data.methods %]
233             # METHODS
234             [% FOR item IN data.methods %]
235             method [% item.name %]() {
236             # do something ...
237              
238             return $self;
239             }
240             [% END -%]
241             [% END -%]
242              
243             [%- IF data.routines %]
244             # ROUTINES
245             [% FOR item IN data.routines %]
246             sub [% item.name %] {
247             my ($self) = @_;
248              
249             # do something ...
250              
251             return $self;
252             }
253             [% END -%]
254             [% END -%]
255              
256             1;
257              
258             @=class-test
259              
260             use 5.014;
261              
262             use strict;
263             use warnings;
264             use routines;
265              
266             use Test::Auto;
267             use Test::More;
268              
269             +=name
270              
271             [% data.name %]
272              
273             +=cut
274              
275             +=abstract
276              
277             [% data.desc %]
278              
279             +=cut
280              
281             [%- IF data.functions || data.methods || data.routines %]
282             +=includes
283              
284             [%- IF data.functions %]
285             [%- FOR item IN data.functions %]
286             function: [% item.name %]
287             [%- END -%]
288             [% END %]
289             [%- IF data.methods %]
290             [%- FOR item IN data.methods %]
291             method: [% item.name %]
292             [%- END -%]
293             [% END %]
294             [%- IF data.routines %]
295             [%- FOR item IN data.routines %]
296             routine: [% item.name %]
297             [%- END -%]
298             [% END %]
299              
300             +=cut
301             [% END -%]
302              
303             +=synopsis
304              
305             use [% data.name %];
306              
307             # do something ...
308              
309             +=cut
310              
311             [%- IF data.libraries %]
312             +=libraries
313              
314             [%- FOR item IN data.libraries %]
315             [% item %]
316             [%- END %]
317              
318             +=cut
319             [% END -%]
320              
321             [%- IF data.inherits %]
322             +=inherits
323              
324             [%- FOR item IN data.inherits %]
325             [% item %]
326             [%- END %]
327              
328             +=cut
329             [% END -%]
330              
331             [%- IF data.integrates %]
332             +=integrates
333              
334             [%- FOR item IN data.integrates %]
335             [% item %]
336             [%- END %]
337              
338             +=cut
339             [% END -%]
340              
341             [%- IF data.attributes %]
342             +=attributes
343              
344             [%- FOR item IN data.attributes %]
345             [% item.name %]: [% item.is %], [% item.form %], [% item.type %]
346             [%- END %]
347              
348             +=cut
349             [% END -%]
350              
351             +=description
352              
353             This package provides [% data.desc %].
354              
355             +=cut
356              
357             [%- IF data.scenarios %]
358             [%- FOR item IN data.scenarios %]
359             +=scenario [% item.name %]
360              
361             This package supports [% item.desc %].
362              
363             +=example [% item.name %]
364              
365             use [% data.name %];
366              
367             # do something ...
368              
369             +=cut
370             [% END -%]
371             [% END -%]
372              
373             [%- IF data.functions %]
374             [%- FOR item IN data.functions %]
375             +=function [% item.name %]
376              
377             The [% item.name %] method [% item.desc %].
378              
379             +=signature [% item.name %]
380              
381             [% item.name %][% item.args %]
382              
383             +=example-1 [% item.name %]
384              
385             # given: synopsis
386              
387             # do something ...
388              
389             +=cut
390             [% END -%]
391             [% END -%]
392              
393             [%- IF data.methods %]
394             [%- FOR item IN data.methods %]
395             +=method [% item.name %]
396              
397             The [% item.name %] method [% item.desc %].
398              
399             +=signature [% item.name %]
400              
401             [% item.name %][% item.args %]
402              
403             +=example-1 [% item.name %]
404              
405             # given: synopsis
406              
407             # do something ...
408              
409             +=cut
410             [% END -%]
411             [% END -%]
412              
413             [%- IF data.routines %]
414             [%- FOR item IN data.routines %]
415             +=routine [% item.name %]
416              
417             The [% item.name %] method [% item.desc %].
418              
419             +=signature [% item.name %]
420              
421             [% item.name %][% item.args %]
422              
423             +=example-1 [% item.name %]
424              
425             # given: synopsis
426              
427             # do something ...
428              
429             +=cut
430             [% END -%]
431             [% END -%]
432              
433             package main;
434              
435             my $test = testauto(__FILE__);
436              
437             my $subs = $test->standard;
438              
439             $subs->synopsis(fun($tryable) {
440             ok my $result = $tryable->result;
441              
442             $result
443             });
444              
445             [%- IF data.scenarios %]
446             [%- FOR item IN data.scenarios %]
447             $subs->scenario('[% item.name %]', fun($tryable) {
448             ok my $result = $tryable->result;
449              
450             $result
451             });
452             [% END -%]
453             [% END -%]
454              
455             [%- IF data.functions %]
456             [%- FOR item IN data.functions %]
457             $subs->example(-1, '[% item.name %]', 'function', fun($tryable) {
458             ok my $result = $tryable->result;
459              
460             $result
461             });
462             [% END -%]
463             [% END -%]
464              
465             [%- IF data.methods %]
466             [%- FOR item IN data.methods %]
467             $subs->example(-1, '[% item.name %]', 'method', fun($tryable) {
468             ok my $result = $tryable->result;
469              
470             $result
471             });
472             [% END -%]
473             [% END -%]
474              
475             [%- IF data.routines %]
476             [%- FOR item IN data.routines %]
477             $subs->example(-1, '[% item.name %]', 'routine', fun($tryable) {
478             ok my $result = $tryable->result;
479              
480             $result
481             });
482             [% END -%]
483             [% END -%]
484              
485             ok 1 and done_testing;