File Coverage

blib/lib/Stenciller/Transformer.pm
Criterion Covered Total %
statement 140 141 99.2
branch 31 56 55.3
condition 4 6 66.6
subroutine 19 19 100.0
pod n/a
total 194 222 87.3


line stmt bran cond sub pod time code
1 6     6   4365 use Stenciller::Standard;
  6         13  
  6         63  
2 6     6   14074 use strict;
  6         13  
  6         186  
3 6     6   35 use warnings;
  6         14  
  6         243  
4              
5             # PODNAME: Stenciller::Transformer
6              
7 6     6   10740 role Stenciller::Transformer using Moose {
  6     6   213  
  6     6   40  
  6         13  
  6         381  
  6         37  
  6         13  
  6         67  
  6         1876  
  6         16  
  6         52  
  6         420  
  6         13  
  6         354  
  6         37  
  6         12  
  6         659  
  6         239  
  6         35  
  6         15  
  6         49  
  6         30002  
  6         16  
  6         69  
  6         35265  
  6         16  
  6         63  
  6         21547  
  6         14  
  6         79  
  6         642  
  6         14  
  6         111  
  6         1528  
  6         16  
  6         80  
  6         8729  
  6         12  
  6         81  
  6         44711  
  6         26  
  6         34  
  6         14  
  6         196  
  6         42  
  6         14  
  6         402  
  6         32  
  6         15  
  6         1079  
  6         64  
  6         32006  
  0         0  
8              
9 6         66 our $VERSION = '0.1302'; # VERSION:
10             # ABSTRACT: A role for transformer plugins to consume
11              
12 6         32 requires 'transform';
13              
14 6         1927 has stenciller => (
15             is => 'ro',
16             isa => Stenciller,
17             required => 1,
18             );
19              
20 6 50   6   83461 method init_out(Stenciller $stenciller, HashRef $transform_args) {
  6 50   6   15  
  6 50   6   1418  
  6 50   7   54  
  6 50       17  
  6 50       1077  
  6 50       39  
  6 50       14  
  6         1030  
  6         1504  
  7         76  
  7         51  
  7         52  
  7         32  
  7         16  
  7         106  
  7         29  
  7         27  
  7         14  
  7         33  
  7         14  
21 7         23 my @out = ('');
22 7 50       379 push (@out => $stenciller->all_header_lines, '') if !$transform_args->{'skip_header_lines'};
23 7         110 return @out;
24             }
25              
26 6 50 33 6   23179 method should_skip_stencil_by_index(Int $index, HashRef $transform_args) {
  6 50   6   17  
  6 50   6   1135  
  6 50   17   33  
  6 50       16  
  6 50       1240  
  6 50       38  
  6 50       13  
  6         1309  
  6         1368  
  17         50  
  17         50  
  17         49  
  17         50  
  17         23  
  17         143  
  17         62  
  17         47  
  17         29  
  17         53  
  17         25  
27 17 100 100 17   113 return 1 if exists $transform_args->{'stencils'} && -1 == first_index { $_ == $index } @{ $transform_args->{'stencils'} };
  17         86  
  12         42  
28 10         64 return 0;
29             }
30              
31 6 50   6   21516 method should_skip_stencil(Stencil $stencil, HashRef $transform_args) {
  6 50   6   17  
  6 50   6   983  
  6 50   10   34  
  6 50       13  
  6 50       905  
  6 50       34  
  6 50       21  
  6         1299  
  6         957  
  10         39  
  10         36  
  10         36  
  10         35  
  10         17  
  10         54  
  10         41  
  10         96  
  10         17  
  10         35  
  10         18  
32 10 100       56 return 0 if !exists $transform_args->{'require_in_extra'};
33 3         7 my $wanted_key = $transform_args->{'require_in_extra'}{'key'};
34 3         6 my $required_value = $transform_args->{'require_in_extra'}{'value'};
35 3         6 my $default_value = $transform_args->{'require_in_extra'}{'default'};
36              
37 3 100       136 return !$default_value if !defined $stencil->get_extra_setting($wanted_key);
38 2         104 return !$stencil->get_extra_setting($wanted_key);
39             }
40             }
41              
42             1;
43              
44             __END__
45              
46             =pod
47              
48             =encoding UTF-8
49              
50             =head1 NAME
51              
52             Stenciller::Transformer - A role for transformer plugins to consume
53              
54             =head1 VERSION
55              
56             Version 0.1302, released 2015-11-28.
57              
58              
59              
60             =head1 SYNOPSIS
61              
62             package Stenciller::Plugin::MyNewRenderer;
63              
64             use Moose;
65             with 'Stenciller::Transformer';
66              
67             sub transformer {
68             ...
69             }
70              
71             =head1 DESCRIPTION
72              
73             This is the role that all L<Stenciller> plugins must consume. It requires a C<transformer> method to be implemented.
74              
75             =head1 METHODS
76              
77             =head2 transform
78              
79             This method must be implemented by classes consuming this role.
80              
81             It takes one attribute:
82              
83             B<C<$transform_args>>
84              
85             C<$transform_args> is a hash reference with the following structure:
86              
87             $transform_args => {
88             skip_header_lines => 0|1,
89             stencils => [...],
90             require_in_extra => {
91             key => '...',
92             value => '...',
93             default => '...',
94             },
95             }
96              
97             B<C<skip_header_lines =E<gt> 1>>
98              
99             C<skip_header_lines> takes a boolean indicating if the L<Stenciller's|Stenciller> header_lines should be skipped. Default is C<0>.
100              
101             B<C<stencils =E<gt> [ ]>>
102              
103             C<stencils> takes an array reference of which stencils in the currently parsed file that should be included in the output. The index is zero based. If C<stencils> is not given, all stencils are parsed.
104              
105             B<C<require_in_extra =E<gt> { }>>
106              
107             C<require_in_extra> allows finer filtering than C<stencils>. Usually, the point to using Stenciller, and
108             related modules, is to use the same content more than once (eg. include it in pod, create html files with
109             examples, and create tests). It is not always necessary to include every stencil in every end product.
110              
111             If C<require_in_extra> is given, it looks in the options hash for every stencil for the C<key> key.
112              
113             =over 4
114              
115             =item *
116              
117             If C<key> exists in the stencil's hash, and it has the C<value> value, then the stencil is parsed.
118              
119             =item *
120              
121             If C<key> exists in the stencil's hash, and it doesn't have the C<value> value, then the stencil is not parsed.
122              
123             =item *
124              
125             If C<key> doesn't exist in the stencil's hash, then the two first rules are applied as if the stencil had the C<default> value.
126              
127             =back
128              
129             =head1 ATTRIBUTES
130              
131             =head2 stenciller
132              
133             The L<Stenciller> object is passed automatically to plugins.
134              
135             =head1 SOURCE
136              
137             L<https://github.com/Csson/p5-Stenciller>
138              
139             =head1 HOMEPAGE
140              
141             L<https://metacpan.org/release/Stenciller>
142              
143             =head1 AUTHOR
144              
145             Erik Carlsson <info@code301.com>
146              
147             =head1 COPYRIGHT AND LICENSE
148              
149             This software is copyright (c) 2015 by Erik Carlsson.
150              
151             This is free software; you can redistribute it and/or modify it under
152             the same terms as the Perl 5 programming language system itself.
153              
154             =cut