File Coverage

blib/lib/Stenciller.pm
Criterion Covered Total %
statement 14 15 93.3
branch n/a
condition n/a
subroutine 5 6 83.3
pod 0 2 0.0
total 19 23 82.6


line stmt bran cond sub pod time code
1 5     5   158912 use 5.14.0;
  5         14  
  5         178  
2 5     5   18 use strict;
  5         7  
  5         139  
3 5     5   19 use warnings;
  5         9  
  5         194  
4              
5 5     5   1604 use Stenciller::Wrap;
  5         13  
  5         593  
6              
7             package Stenciller;
8              
9             our $VERSION = '0.1212'; # VERSION:
10             # PODCLASSNAME:
11             # ABSTRACT: Transforms a flat file format to different output
12              
13             sub new {
14 5     5 0 2904 shift;
15 5         275 Stenciller::Wrap->new(@_);
16             }
17             sub meta {
18 0     0 0   Stenciller::Wrap->meta;
19             }
20              
21             1;
22              
23             __END__
24              
25             =pod
26              
27             =encoding UTF-8
28              
29             =head1 NAME
30              
31             Stenciller - Transforms a flat file format to different output
32              
33             =head1 VERSION
34              
35             Version 0.1212, released 2015-02-10.
36              
37              
38              
39             =head1 SYNOPSIS
40              
41             use Stenciller;
42             my $stenciller = Stenciller->new(filepath => 't/corpus/test-1.stencil');
43             my $content = $stenciller->transform(plugin_name => 'ToUnparsedText');
44              
45             =head1 DESCRIPTION
46              
47             Stenciller reads a special fileformat and provides a way to convert the content into different types of output. For example, it can be used to create documentation and tests from the same source file.
48              
49             =head2 File format
50              
51             == stencil {} ==
52              
53             --input--
54              
55             --end input--
56              
57             --output--
58              
59             --end output--
60              
61             This is the basic layout. A stencil ends when a new stencil block is discovered (there is no set limit to the number of stencils in a file). The (optional) hash is for settings. Each stencil has five parts: C<before_input>, C<input>, C<between>, C<output> and C<after_output>. In addition to this
62             there is a header before the first stencil.
63              
64             =head1 ATTRIBUTES
65              
66              
67             =head2 filepath
68              
69             =begin HTML
70              
71             <table cellpadding="0" cellspacing="0">
72             <tr><td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Path::Tiny#File">File</a>
73              
74             </td>
75             <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">required</td>
76             <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read-only</td></tr>
77             </table>
78              
79             <p>The textfile to parse.</p>
80              
81             =end HTML
82              
83             =head2 is_utf8
84              
85             =begin HTML
86              
87             <table cellpadding="0" cellspacing="0">
88             <tr><td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#Bool">Bool</a>
89              
90             </td>
91             <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">optional, default: <code>1</code>
92              
93             </td>
94             <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read-only</td></tr>
95             </table>
96              
97             <p>Determines how the stencil file is read.</p>
98              
99             =end HTML
100              
101             =head2 skip_if_input_empty
102              
103             =begin HTML
104              
105             <table cellpadding="0" cellspacing="0">
106             <tr><td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#Bool">Bool</a>
107              
108             </td>
109             <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">optional, default: <code>1</code>
110              
111             </td>
112             <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read-only</td></tr>
113             </table>
114              
115             <p>If a stencil has no input content, skip entire stencil.</p>
116              
117             =end HTML
118              
119             =head2 skip_if_output_empty
120              
121             =begin HTML
122              
123             <table cellpadding="0" cellspacing="0">
124             <tr><td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#Bool">Bool</a>
125              
126             </td>
127             <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">optional, default: <code>1</code>
128              
129             </td>
130             <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read-only</td></tr>
131             </table>
132              
133             <p>If a stencil has no output content, skip entire stencil.</p>
134              
135             =end HTML
136              
137             =head2 header_lines
138              
139             =begin HTML
140              
141             <table cellpadding="0" cellspacing="0">
142             <tr><td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#ArrayRef">ArrayRef</a> [ <a href="https://metacpan.org/pod/Types::Standard#Str">Str</a> ]</td>
143             <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">not in constructor</td>
144             <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read-only</td></tr>
145             </table>
146              
147             <p>After parsing, this contains all lines in the header.</p>
148              
149             =end HTML
150              
151             =head2 stencils
152              
153             =begin HTML
154              
155             <table cellpadding="0" cellspacing="0">
156             <tr><td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;"><a href="https://metacpan.org/pod/Types::Standard#ArrayRef">ArrayRef</a> [ <a href="https://metacpan.org/pod/Types::Stenciller#Stencil">Stencil</a> ]</td>
157             <td style="padding-right: 6px; padding-left: 6px; border-right: 1px solid #b8b8b8; white-space: nowrap;">not in constructor</td>
158             <td style="padding-left: 6px; padding-right: 6px; white-space: nowrap;">read-only</td></tr>
159             </table>
160              
161             <p>After parsing, this contains all parsed stencils.</p>
162              
163             =end HTML
164              
165             =head1 METHODS
166              
167              
168             =head2 transform
169              
170             =begin HTML
171              
172             <p></p>
173              
174             <!-- -->
175             <table style="margin-bottom: 10px; margin-left: 10px; border-collapse: bollapse;" cellpadding="0" cellspacing="0">
176              
177             <tr style="vertical-align: top;"><td style="text-align: left; color: #444; padding-left: 5px; font-weight: bold; background-color: #e8eee8;">Named parameters</td><td style="text-align: left; color: #444; padding-left: 5px; font-weight: bold; background-color: #e8eee8;">&#160;</td><td style="text-align: left; color: #444; padding-left: 5px; font-weight: bold; background-color: #e8eee8;">&#160;</td><td style="text-align: left; color: #444; padding-left: 5px; font-weight: bold; background-color: #e8eee8;">&#160;</td><td style="text-align: left; color: #444; padding-left: 5px; font-weight: bold; background-color: #e8eee8;">&#160;</td></tr>
178             <tr style="vertical-align: top;">
179             <td style="vertical-align: top; border-right: 1px solid #eee; white-space: nowrap; padding: 3px 6px; border-bottom: 1px solid #eee;"><code>plugin_name =&gt; $value</code>
180              
181             </td>
182             <td style="vertical-align: top; border-right: 1px solid #eee; white-space: nowrap; padding: 3px 6px; border-bottom: 1px solid #eee;"><a href="https://metacpan.org/pod/Types::Standard#Str">Str</a>
183              
184             </td>
185             <td style="vertical-align: top; border-right: 1px solid #eee; white-space: nowrap; padding: 3px 6px; border-bottom: 1px solid #eee;">required</td>
186             <td style="vertical-align: top; border-right: 1px solid #eee; white-space: nowrap; border-bottom: 1px solid #eee;"></td>
187             <td style="padding: 3px 6px; vertical-align: top; border-bottom: 1px solid #eee;">Plugin to read contents with.</td>
188             </tr>
189             <tr style="vertical-align: top;">
190             <td style="vertical-align: top; border-right: 1px solid #eee; white-space: nowrap; padding: 3px 6px; border-bottom: 1px solid #eee;"><code>constructor_args =&gt; $value</code>
191              
192             </td>
193             <td style="vertical-align: top; border-right: 1px solid #eee; white-space: nowrap; padding: 3px 6px; border-bottom: 1px solid #eee;"><a href="https://metacpan.org/pod/Types::Standard#HashRef">HashRef</a>
194              
195             </td>
196             <td style="vertical-align: top; border-right: 1px solid #eee; white-space: nowrap; padding: 3px 6px; border-bottom: 1px solid #eee;">optional, default <code>= { }</code>
197              
198             </td>
199             <td style="vertical-align: top; border-right: 1px solid #eee; white-space: nowrap; border-bottom: 1px solid #eee;"></td>
200             <td style="padding: 3px 6px; vertical-align: top; border-bottom: 1px solid #eee;">Constructor arguments for the plugin.</td>
201             </tr>
202             <tr style="vertical-align: top;">
203             <td style="vertical-align: top; border-right: 1px solid #eee; white-space: nowrap; padding: 3px 6px; border-bottom: 1px solid #eee;"><code>transform_args =&gt; $value</code>
204              
205             </td>
206             <td style="vertical-align: top; border-right: 1px solid #eee; white-space: nowrap; padding: 3px 6px; border-bottom: 1px solid #eee;"><a href="https://metacpan.org/pod/Types::Standard#HashRef">HashRef</a>
207              
208             </td>
209             <td style="vertical-align: top; border-right: 1px solid #eee; white-space: nowrap; padding: 3px 6px; border-bottom: 1px solid #eee;">optional, default <code>= { }</code>
210              
211             </td>
212             <td style="vertical-align: top; border-right: 1px solid #eee; white-space: nowrap; border-bottom: 1px solid #eee;"></td>
213             <td style="padding: 3px 6px; vertical-align: top; border-bottom: 1px solid #eee;">Settings for the specific transformation.</td>
214             </tr>
215             <tr style="vertical-align: top;"><td style="text-align: left; color: #444; padding-left: 5px; font-weight: bold; background-color: #e8e8ee;">Returns</td><td style="text-align: left; color: #444; padding-left: 5px; font-weight: bold; background-color: #e8e8ee;">&#160;</td><td style="text-align: left; color: #444; padding-left: 5px; font-weight: bold; background-color: #e8e8ee;">&#160;</td><td style="text-align: left; color: #444; padding-left: 5px; font-weight: bold; background-color: #e8e8ee;">&#160;</td><td style="text-align: left; color: #444; padding-left: 5px; font-weight: bold; background-color: #e8e8ee;">&#160;</td></tr>
216             <tr style="vertical-align: top;">
217             <td style="vertical-align: top; border-right: 1px solid #eee; padding: 3px 6px; border-bottom: 1px solid #eee;"><a href="https://metacpan.org/pod/Types::Standard#Str">Str</a>
218              
219             </td><td style="vertical-align: top; border-right: 1px solid #eee; padding: 3px 6px; border-bottom: 1px solid #eee;">&#160;</td><td style="vertical-align: top; border-right: 1px solid #eee; padding: 3px 6px; border-bottom: 1px solid #eee;">&#160;</td><td style="vertical-align: top; border-right: 1px solid #eee; padding: 3px 6px; border-bottom: 1px solid #eee;">&#160;</td>
220             <td style="padding: 3px 6px; vertical-align: top; border-bottom: 1px solid #eee;">The transformed content.</td>
221             </tr>
222             </table>
223              
224             =end HTML
225              
226             =head1 PLUGINS
227              
228             The actual transforming is done by plugins. There are two plugins bundled in this distribution:
229              
230             =over 4
231              
232             =item *
233              
234             L<Stenciller::Plugin::ToUnparsedText>
235              
236             =item *
237              
238             L<Stenciller::Plugin::ToHtmlPreBlock>
239              
240             =back
241              
242             Custom plugins should be in the L<Stenciller::Plugin> namespace and consume the L<Stenciller::Transformer> role.
243              
244             =head1 SOURCE
245              
246             L<https://github.com/Csson/p5-Stenciller>
247              
248             =head1 HOMEPAGE
249              
250             L<https://metacpan.org/release/Stenciller>
251              
252             =head1 AUTHOR
253              
254             Erik Carlsson <info@code301.com>
255              
256             =head1 COPYRIGHT AND LICENSE
257              
258             This software is copyright (c) 2015 by Erik Carlsson <info@code301.com>.
259              
260             This is free software; you can redistribute it and/or modify it under
261             the same terms as the Perl 5 programming language system itself.
262              
263             =cut