blib/lib/Pod/Elemental/Transformer/Stenciller.pm

filter: Statementstmt 95.4% 84 / 88 Branchbran 62.5% 10 / 16 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 94.4% 17 / 18 Podpod 0.0% 0 / 2 totaltotal 86.8% 112 / 129 CC 11 SCAR 12.4
CC
11
Cov
89%
transform_node
8.4
ensure_plugin
3.1
__ANON__
2.0
CRAP 3.5
↑ Summary
1 2 ▶use 5.10.1;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package Pod::Elemental::Transformer::Stenciller;
6  
7 # ABSTRACT: Injects content from textfiles transformed with Stenciller
8 2 our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
9 2 our $VERSION = '0.0301';
10  
11 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 2 ▶use MooseX::AttributeDocumented;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 2 with qw/Pod::Elemental::Transformer Stenciller::Utils/;
14  
15 2 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 2 ▶use Types::Standard -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use Types::Path::Tiny qw/Dir/;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use Types::Stenciller qw/Stenciller/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 2 ▶use Carp qw/carp croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 2 ▶use Module::Load qw/load/;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use Stenciller;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 2 has directory => (
25 is => 'ro',
26 isa => Dir,
27 coerce => 1,
28 required => 1,
29 documentation => 'Path to directory where the stencil files are.'
30 );
31 has settings => (
32 is => 'ro',
33 isa => HashRef,
34 traits => ['Hash'],
35 0 ▶ default => sub { +{} },
Subroutine __ANON__: not called CC=1 SCAR=6.9
36 2 handles => {
37 get_setting => 'get',
38 set_setting => 'set',
39 all_settings => 'elements',
40 },
41 documentation_default => '{ }',
42 documentation_order => 0,
43 documentation => 'If a plugin takes more attributes..',
44 );
45 has plugins => (
46 is => 'ro',
47 isa => HashRef,
48 1 ▶ default => sub { +{} },
Subroutine __ANON__: called CC=1 SCAR=0.0
49 2 documentation_default => '{ }',
50 documentation_order => 0,
51 init_arg => undef,
52 traits => ['Hash'],
53 handles => {
54 get_plugin => 'get',
55 set_plugin => 'set',
56 },
57 documentation_order => 0,
58 );
59 2 has stencillers => (
60 is => 'ro',
61 isa => HashRef,
62 traits => ['Hash'],
63 init_arg => undef,
64 handles => {
65 get_stenciller_for_filename => 'get',
66 set_stenciller_for_filename => 'set',
67 },
68 documentation_order => 0,
69 );
70  
71 1 ▶around BUILDARGS => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
72 1 my $next = shift;
73 1 my $class = shift;
74 1 my @args = @_;
75  
76 1 ▶ my $args = ref $args[0] eq 'HASH' ? $args[0] : { @args };
Branch: 1 branch
BranchTrueFalseTotal
ref $args[0] eq 'HASH' ? : 0 1 1
77  
78 $class->$next(
79 1 directory => delete $args->{'directory'},
80 settings => $args
81 );
82 2 };
83  
84 1 ▶sub transform_node {
Subroutine transform_node: called CC=8 SCAR=21.3
Pod undocumented
85 1 my $self = shift;
86 1 my $main_node = shift;
87  
88 NODE:
89 1 foreach my $node (@{ $main_node->children }) {
90 5 my $content = $node->content;
91 5 my $start = substr($content, 0, 11, '');
92 5 ▶ next NODE if $start ne ':stenciller';
Branch: 1 branch
BranchTrueFalseTotal
if $start ne ":stenciller" 3 2 5
93  
94 2 $content =~ s{^\h+}{}; # remove leading whitespace
95 2 ▶ next if $content !~ m{([^\h\v]+)}; # the next sequence of non-space is the wanted plugin name
Branch: 1 branch
BranchTrueFalseTotal
unless $content =~ /([^\h\v]+)/ 0 2 2
96  
97 2 my $wanted_plugin = $1;
98 2 my $plugin_name = $self->ensure_plugin($wanted_plugin);
99  
100 2 (undef, my($filename, $possible_hash)) = split /\h+/ => $content, 3;
101 2 chomp $filename;
102 2 ▶ my $node_settings = defined $possible_hash && $possible_hash =~ m{\{.*\}} ? $self->eval_to_hashref($possible_hash, $filename) : {};
Branch: 1 branch
BranchTrueFalseTotal
defined $possible_hash && $possible_hash =~ /\{.*\}/ ? : 2 0 2
Condition33%1/3
defined $possible_hash and $possible_hash =~ /\{.*\}/
!ll&&!rl&&r
002
MC/DC0%0/2
defined $possible_hash and $possible_hash =~ /\{.*\}/
defined $possible_hash $possible_hash =~ /\{.*\}/
Truth table33%1/3
A and B
A= defined $possible_hashB= $possible_hash =~ /\{.*\}/
ABresult
0X0
100
111
103  
104 2 my $stenciller = $self->get_stenciller_for_filename($filename);
105  
106 2 ▶ if(!Stenciller->check($stenciller)) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&Stenciller()->check($stenciller)) 1 1 2
107 1 $stenciller = Stenciller::->new(filepath => path($self->directory)->child($filename));
108 1 ▶ if(!$stenciller->has_stencils) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($stenciller->has_stencils) 0 1 1
109 0 carp sprintf '! no stencils in %s/%s - skipping', $self->directory, $filename;
110 0 return;
111 }
112  
113 1 $self->set_stenciller_for_filename($filename => $stenciller);
114 }
115  
116 2 my $transformed_content = $stenciller->transform(plugin_name => $plugin_name,
117 constructor_args => $self->settings,
118 transform_args => { %$node_settings, require_in_extra => { key => 'to_pod', value => 1, default => 1 } },
119 );
120 2 $transformed_content =~ s{[\v\h]+$}{};
121 2 $node->content($transformed_content);
122  
123 }
124 }
125 2 ▶sub ensure_plugin {
Subroutine ensure_plugin: called CC=3 SCAR=11.3
Pod undocumented
126 2 my $self = shift;
127 2 my $plugin_name = shift;
128  
129 2 ▶ return $self->get_plugin($plugin_name) if $self->get_plugin($plugin_name);
Branch: 1 branch
BranchTrueFalseTotal
if $self->get_plugin($plugin_name) 0 2 2
130  
131 2 my $plugin_class = sprintf 'Stenciller::Plugin::%s', $plugin_name;
132 2 load($plugin_class);
133  
134 2 ▶ if(!$plugin_class->does('Stenciller::Transformer')) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($plugin_class->does("Stenciller::Transformer")) 0 2 2
135 0 croak("[$plugin_name] doesn't do the Stenciller::Transformer role. Quitting.");
136 }
137 2 $self->set_plugin($plugin_name => $plugin_name);
138 2 return $plugin_name;
139 }
140  
141 2 __PACKAGE__->meta->make_immutable;
142  
143 2 1;
144  
145 __END__
↑ Summary