File Coverage

lib/Pod/PseudoPod/Book/Command.pm
Criterion Covered Total %
statement 15 61 24.5
branch 0 8 0.0
condition 0 2 0.0
subroutine 5 14 35.7
pod 1 9 11.1
total 21 94 22.3


line stmt bran cond sub pod time code
1             package Pod::PseudoPod::Book::Command;
2             # ABSTRACT: base class for all ppbook commands
3              
4 2     2   13549 use strict;
  2         5  
  2         74  
5 2     2   14 use warnings;
  2         4  
  2         114  
6              
7 2     2   601 use App::Cmd::Setup -command;
  2         40367  
  2         19  
8 2     2   499 use File::Spec;
  2         6  
  2         62  
9 2     2   1466 use File::Slurp ();
  2         58005  
  2         1828  
10              
11             sub config
12             {
13 0     0 0   my ($self, $path) = @_;
14 0   0       $path ||= '.';
15 0           my $conf_file = File::Spec->catfile( $path, 'book.conf' );
16 0           return Config::Tiny->read( $conf_file );
17             }
18              
19             sub opt_spec
20             {
21 0     0 1   my ($class, $app) = @_;
22 0           return $class->options( $app );
23             }
24              
25             sub options
26             {
27 0     0 0   my ($self, $app) = @_;
28 0           my $conf = $app->config;
29              
30             return
31             [
32             'author_name=s' => "Author's name",
33             { default => $conf->{book}{author_name} },
34              
35             'copyright_year=s' => 'Copyright year',
36             { default => $conf->{book}{copyright_year} },
37              
38             'cover_image=s' => 'Path to cover image',
39             { default => $conf->{book}{cover_image} },
40              
41             'language=s' => 'Language code for contents',
42             { default => $conf->{book}{language} },
43              
44             'title=s' => 'Book title',
45             { default => $conf->{book}{title} },
46 0           ];
47             }
48              
49             sub get_build_prefix
50             {
51 0     0 0   my $self = shift;
52 0           my $chapter_build_dir = $self->config->{layout}{chapter_build_directory};
53 0           return File::Spec->catdir( 'build', $chapter_build_dir );
54             }
55              
56             sub get_built_chapters
57             {
58 0     0 0   my $self = shift;
59 0           my $conf = $self->config;
60 0           my $chapter_prefix = $conf->{layout}{chapter_name_prefix};
61             my $glob = $conf->{book}{build_chapters}
62 0 0         ? "${chapter_prefix}_*.pod"
63             : '*.pod';
64              
65 0           return glob File::Spec->catfile( $self->get_build_prefix, $glob );
66             }
67              
68             sub get_built_html
69             {
70 0     0 0   my ($self, $suffix) = @_;
71 0           my @order = $self->chapter_order;
72              
73 0 0         return glob File::Spec->catfile( qw( build html ), "*.$suffix" )
74             unless @order;
75              
76 0 0         push @order, 'theindex' if $self->config->{book}{build_index};
77              
78 0           return map { File::Spec->catfile( qw( build html ), "$_.$suffix" ) }
  0            
79             @order;
80             }
81              
82             sub get_anchor_list
83             {
84 0     0 0   my ($self, $suffix) = splice @_, 0, 2;
85 0           my $chapter_prefix = $self->config->{layout}{chapter_name_prefix};
86 0           my %anchors;
87              
88 0           for my $chapter (@_)
89             {
90 0           my ($file) = $chapter =~ /(${chapter_prefix}_\d+)./;
91 0           my $contents = File::Slurp::read_file($chapter);
92              
93 0           while ($contents =~ /(?:^=head\d (.*?)|\A)\n\nZ<(.*?)>/mg)
94             {
95 0           $anchors{$2} = [ $file . $suffix, $1 ];
96             }
97             }
98              
99 0           return \%anchors;
100             }
101              
102             sub chapter_order
103             {
104 0     0 0   my $self = shift;
105 0           my $config = $self->config;
106 0 0         return unless my $order = $config->{chapter_order};
107              
108 0           return map { $order->{$_} } sort { $a <=> $b } keys %$order;
  0            
  0            
109             }
110              
111             sub map_chapters_to_output
112             {
113 0     0 0   my ($self, $suffix, $dir) = splice @_, 0, 3;
114 0           my $conf = $self->config;
115 0           my $build_dir = $conf->{layout}{chapter_build_directory};
116              
117             return map
118             {
119 0           my $dest = $_;
  0            
120 0           $dest =~ s!/$build_dir/!/$dir/!;
121 0           $dest =~ s/\.pod$/\.$suffix/;
122 0           [ $_ => $dest ];
123             } @_;
124             }
125              
126             1;
127              
128             __END__
129              
130             =pod
131              
132             =encoding UTF-8
133              
134             =head1 NAME
135              
136             Pod::PseudoPod::Book::Command - base class for all ppbook commands
137              
138             =head1 VERSION
139              
140             version 1.20210620.2051
141              
142             =head1 AUTHOR
143              
144             chromatic <chromatic@wgz.org>
145              
146             =head1 COPYRIGHT AND LICENSE
147              
148             This software is copyright (c) 2011 by chromatic.
149              
150             This is free software; you can redistribute it and/or modify it under
151             the same terms as the Perl 5 programming language system itself.
152              
153             =cut