File Coverage

blib/lib/Stenciller/Plugin/ToUnparsedText.pm
Criterion Covered Total %
statement 26 26 100.0
branch 3 4 75.0
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 36 37 97.3


line stmt bran cond sub pod time code
1 2     2   990 use 5.14.0;
  2         5  
  2         82  
2 2     2   9 use strict;
  2         3  
  2         69  
3 2     2   7 use warnings;
  2         4  
  2         119  
4              
5             package Stenciller::Plugin::ToUnparsedText;
6             our $VERSION = '0.1212'; # VERSION:
7             # ABSTRACT: A plugin that doesn't transform the text
8              
9 2     2   9 use Moose;
  2         2  
  2         16  
10 2     2   12066 use List::AllUtils qw/first_index/;
  2         4  
  2         691  
11             with 'Stenciller::Transformer';
12              
13             sub transform {
14 2     2 1 756 my $self = shift;
15 2         5 my $transform_args = shift;
16              
17 2         53 my @out = $self->init_out($self->stenciller, $transform_args);
18              
19             STENCIL:
20 2         51 for my $i (0 .. $self->stenciller->max_stencil_index) {
21 3 100       26 next STENCIL if $self->should_skip_stencil_by_index($i, $transform_args);
22              
23 2         58 my $stencil = $self->stenciller->get_stencil($i);
24 2 50       88 next STENCIL if $self->should_skip_stencil($stencil, $transform_args);
25              
26 2         74 push @out => '',
27             $stencil->all_before_input, '',
28             $stencil->all_input, '',
29             $stencil->all_between, '',
30             $stencil->all_output, '',
31             $stencil->all_after_output, '';
32             }
33 2         346 my $content = join "\n" => '', @out, '';
34 2         22 $content =~ s{[\r?\n]{2,}}{\n\n}g;
35 2         23 return $content;
36             }
37              
38             1;
39              
40             __END__
41              
42             =pod
43              
44             =encoding UTF-8
45              
46             =head1 NAME
47              
48             Stenciller::Plugin::ToUnparsedText - A plugin that doesn't transform the text
49              
50             =head1 VERSION
51              
52             Version 0.1212, released 2015-02-10.
53              
54              
55              
56             =head1 SYNOPSIS
57              
58             use Stenciller;
59             my $stenciller = Stenciller->new(filepath => 't/corpus/test-1.stencil');
60             my $content = $stenciller->transform('ToUnparsedText');
61              
62             =head1 DESCRIPTION
63              
64             This plugin to L<Stenciller> basically returns all text content of the stencils.
65              
66             If this plugin is used via L<Pod::Elemental::Transformer::Stenciller> it could be used like this in pod:
67              
68             =pod
69              
70             # includes header_lines and all stencils
71             :stenciller ToUnparsedText atestfile-1.stencil
72              
73             # includes header_lines and all stencils
74             :stenciller ToUnparsedText atestfile-1.stencil { }
75              
76             # includes only the first stencil in the file
77             :stenciller ToUnparsedText atestfile-1.stencil { stencils => [0], skip_header_lines => 1 }
78              
79             # includes only the header_lines
80             :stenciller ToUnparsedText atestfile-1.stencil { stencils => [] }
81              
82             =head1 METHODS
83              
84             =head2 transform
85              
86             See L<transform|Stenciller::Transformer/"transform"> in L<Stenciller::Transformer>.
87              
88             =head1 SOURCE
89              
90             L<https://github.com/Csson/p5-Stenciller>
91              
92             =head1 HOMEPAGE
93              
94             L<https://metacpan.org/release/Stenciller>
95              
96             =head1 AUTHOR
97              
98             Erik Carlsson <info@code301.com>
99              
100             =head1 COPYRIGHT AND LICENSE
101              
102             This software is copyright (c) 2015 by Erik Carlsson <info@code301.com>.
103              
104             This is free software; you can redistribute it and/or modify it under
105             the same terms as the Perl 5 programming language system itself.
106              
107             =cut