blib/lib/Dist/Zilla/Plugin/Documentation/SQL.pm

filter: Statementstmt 100% 57 / 57 Branchbran 75.0% 3 / 4 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 10 / 10 Podpod 100% 3 / 3 totaltotal 98.7% 78 / 79 CC 5 SCAR 8.9
CC
5
Cov
98%
munge_files
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 2.4
↑ Summary
1 package Dist::Zilla::Plugin::Documentation::SQL;
2 {
3 1 $Dist::Zilla::Plugin::Documentation::SQL::VERSION = '0.03';
4 }
5  
6 # ABSTRACT: Create a file gathering all =sql commands
7  
8  
9 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Pod::Elemental;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Pod::Elemental::Element::Nested;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use Pod::Weaver::Section::SQL 0.03;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 with qw/
19 Dist::Zilla::Role::FileInjector
20 Dist::Zilla::Role::FileMunger
21 Dist::Zilla::Role::Plugin
22 /;
23  
24 1 with 'Dist::Zilla::Role::FileFinderUser' =>
25 { default_finders => [ ':InstallModules', ], };
26  
27  
28 1 ▶sub documentation_dir {
Subroutine documentation_dir: called CC=1 SCAR=0.0
Pod documented
29 1 my ($self) = @_;
30 1 ( my $package = $self->zilla->name ) =~ s@-@/@g;
31 1 my $package_dir = dir("lib/$package");
32 1 my $documentation_dir = $package_dir->subdir('Documentation');
33 1 $documentation_dir->mkpath;
34 1 return $documentation_dir;
35 }
36  
37  
38 1 ▶sub documentation_file {
Subroutine documentation_file: called CC=1 SCAR=0.0
Pod documented
39 1 my ($self) = @_;
40 1 my $documentation_file = $self->documentation_dir->file('SQL.pod');
41 1 return $documentation_file . "";
42 }
43  
44  
45 1 ▶sub munge_files {
Subroutine munge_files: called CC=5 SCAR=16.1
Pod documented
46 1 my ($self) = @_;
47  
48 1 my $document = Pod::Elemental::Document->new;
49  
50 1 for my $file ( @{ $self->found_files } ) {
51 1 my $file_section = Pod::Elemental::Element::Nested->new(
52 command => 'head1',
53 content => $file->name,
54 );
55  
56 $file_section->children(
57 [
58  
59 # Remove the '=sql' command part
60 map {
61 1 my $formatter = Pod::Weaver::Section::SQL->new(
62 plugin_name => 'Pod::Weaver::Section::SQL',
63 weaver => bless({}, 'Pod::Weaver'),
64 );
65 1 Pod::Elemental::Element::Pod5::Ordinary->new(
66 content => $formatter->format_sql($_->content) )
67 }
68  
69 # Keep only sql commands content
70 grep {
71 5 ▶ $_
Branch: 1 branch
BranchTrueFalseTotal
if $_->can("command") and $_->command eq "sql" 1 4 5
Condition100%3/3
$_->can("command") and $_->command eq "sql"
!ll&&!rl&&r
311
MC/DC100%2/2
$_->can("command") and $_->command eq "sql"
$_->can("command") $_->command eq "sql"
Truth table100%3/3
A and B
A= $_->can("command")B= $_->command eq "sql"
ABresult
0X0
100
111
72 if ( $_->can('command') and $_->command eq 'sql' );
73 1 } @{ Pod::Elemental->read_file( $file->name )->children }
74 ]
75 );
76  
77 1 ▶ if ( @{ $file_section->children } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$file_section->children;}) 1 0 1
78  
79 1 my $file_package = $file->name;
80 1 $file_package =~ s,lib/,,g;
81 1 $file_package =~ s,\.pm,,g;
82 1 $file_package =~ s,/,::,g;
83  
84 # Push front of children a link to the file
85 $file_section->children(
86 [
87 Pod::Elemental::Element::Pod5::Ordinary->new(
88 content => "L<$file_package>",
89 ),
90 1 @{ $file_section->children }
91 ]
92 );
93  
94 # Push-back
95 1 $document->children( [ @{ $document->children }, $file_section ] );
96 }
97 }
98  
99 $self->add_file(
100 1 Dist::Zilla::File::InMemory->new(
101 name => $self->documentation_file,
102 content => $document->as_pod_string,
103 )
104 );
105 1 return;
106 }
107  
108 1 1;
109  
110 __END__
↑ Summary