File Coverage

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