| 1 | 6 | ▶ | use Stenciller::Standard; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 2 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 3 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||
| 5 | # PODNAME: Stenciller::Transformer | ||||||||||||||||||||||||||||||||||||||
| 6 | 6 | ||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | role Stenciller::Transformer using Moose { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||
| 9 | 6 | our $VERSION = '0.1302'; # VERSION: | |||||||||||||||||||||||||||||||||||||
| 10 | # ABSTRACT: A role for transformer plugins to consume | ||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||
| 12 | 6 | requires 'transform'; | |||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||
| 14 | 6 | has stenciller => ( | |||||||||||||||||||||||||||||||||||||
| 15 | is => 'ro', | ||||||||||||||||||||||||||||||||||||||
| 16 | isa => Stenciller, | ||||||||||||||||||||||||||||||||||||||
| 17 | required => 1, | ||||||||||||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||
| 20 | 6 | ▶ | method init_out(Stenciller $stenciller, HashRef $transform_args) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
init_out: called CC=10 SCAR=23.8
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||
| 21 | 7 | my @out = (''); | |||||||||||||||||||||||||||||||||||||
| 22 | 7 | ▶ | push (@out => $stenciller->all_header_lines, '') if !$transform_args->{'skip_header_lines'}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 23 | 7 | return @out; | |||||||||||||||||||||||||||||||||||||
| 24 | } | ||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||
| 26 | 6 | ▶ | method should_skip_stencil_by_index(Int $index, HashRef $transform_args) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
should_skip_stencil_by_index: called CC=11 SCAR=24.5
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||
| 27 | 17 | ▶ | return 1 if exists $transform_args->{'stencils'} && -1 == first_index { $_ == $index } @{ $transform_args->{'stencils'} }; | ||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
Branch: 1 branch
Condition100%3/3
exists $transform_args->{"stencils"} and -1 == &first_index(sub {
MC/DC100%2/2
exists $transform_args->{"stencils"} and -1 == &first_index(sub {
$_ == $index;
}
, @{$$transform_args{"stencils"};})
exists $transform_args->{"stencils"}
-1 == &first_index(sub {
$_ == $index;
}
, @{$$transform_args{"stencils"};})
Truth table100%3/3
A and B
A= exists $transform_args->{"stencils"}B= -1 == &first_index(sub {
$_ == $index;
}
, @{$$transform_args{"stencils"};})
| |||||||||||||||||||||||||||||||||||||||
| 28 | 10 | return 0; | |||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||
| 31 | 6 | ▶ | method should_skip_stencil(Stencil $stencil, HashRef $transform_args) { | ||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
BEGIN: called CC=1 SCAR=0.1
Subroutine
should_skip_stencil: called CC=11 SCAR=24.4
Branch: 8 branches
| |||||||||||||||||||||||||||||||||||||||
| 32 | 10 | ▶ | return 0 if !exists $transform_args->{'require_in_extra'}; | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 33 | 3 | my $wanted_key = $transform_args->{'require_in_extra'}{'key'}; | |||||||||||||||||||||||||||||||||||||
| 34 | 3 | my $required_value = $transform_args->{'require_in_extra'}{'value'}; | |||||||||||||||||||||||||||||||||||||
| 35 | 3 | my $default_value = $transform_args->{'require_in_extra'}{'default'}; | |||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||
| 37 | 3 | ▶ | return !$default_value if !defined $stencil->get_extra_setting($wanted_key); | ||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||
| 38 | 2 | return !$stencil->get_extra_setting($wanted_key); | |||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||
| 42 | 6 | 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 | ||||||||||||||||||||||||||||||||||||||