lib/App/Followme/CreateIndex.pm

filter: Statementstmt 95.8% 69 / 72 Branchbran 57.1% 8 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 15 / 15 Podpod 33.3% 2 / 6 totaltotal 84.8% 95 / 112 CC 11 SCAR 11.7
CC
11
Cov
88%
sections_are_filled
6.3
update_folder
5.4
no_recurse
2.0
CRAP 3.2
« lib/App/Followme/ConvertPage.pm ↑ Summary lib/App/Followme.pm »
1 package App::Followme::CreateIndex;
2 3 ▶use 5.008005;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use lib '../..';
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 3 ▶use base qw(App::Followme::Module);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 3 ▶use IO::Dir;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use File::Spec::Functions qw(abs2rel rel2abs splitdir catfile no_upwards);
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 3 ▶use App::Followme::FIO;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 3 ▶use App::Followme::Web;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 3 our $VERSION = "2.03";
17  
18 #----------------------------------------------------------------------
19 # Read the default parameter values
20  
21 52 ▶sub parameters {
Subroutine parameters: called CC=1 SCAR=0.0
Pod documented
22 52 my ($pkg) = @_;
23  
24 return (
25 52 template_file => 'create_index.htm',
26 data_pkg => 'App::Followme::WebData',
27 );
28 }
29  
30 #----------------------------------------------------------------------
31 # Create an index to all files in a folder with a specified extension
32  
33 12 ▶sub run {
Subroutine run: called CC=1 SCAR=0.0
Pod undocumented
34 12 my ($self, $folder) = @_;
35  
36 12 eval {$self->update_folder($folder)};
37 12 $self->check_error($@, $folder);
38  
39 12 return;
40 }
41  
42 #----------------------------------------------------------------------
43 # Return a flag indicating that recursion on folders is not needed
44  
45 12 ▶sub no_recurse {
Subroutine no_recurse: called CC=2 SCAR=7.0
Pod undocumented
46 12 my ($self) = @_;
47  
48 12 my $template_file = $self->get_template_name($self->{template_file});
49 12 my $template = fio_read_page($template_file);
50 12 ▶ die "Couldn't read template: $template_file" unless $template;
Branch: 1 branch
BranchTrueFalseTotal
unless $template 0 12 12
51  
52 12 return web_has_variables($template, '@all_files', '@top_files');
53 }
54  
55 #----------------------------------------------------------------------
56 # Return true if each section in a file has been filled from the template
57  
58 1 ▶sub sections_are_filled {
Subroutine sections_are_filled: called CC=6 SCAR=18.4
Pod undocumented
59 1 my ($self, $filename) = @_;
60  
61 1 my $page = fio_read_page($filename);
62 1 ▶ return unless $page;
Branch: 1 branch
BranchTrueFalseTotal
unless $page 0 1 1
63 1 my $page_sections = web_parse_sections($page);
64  
65 1 my $template_file = $self->get_template_name($self->{template_file});
66 1 my $template = fio_read_page($template_file);
67 1 ▶ die "Couldn't read template: $template_file" unless $template;
Branch: 1 branch
BranchTrueFalseTotal
unless $template 0 1 1
68 1 my $template_sections = web_parse_sections($template);
69  
70 1 foreach my $name (keys %$template_sections) {
71 2 ▶ next unless $template_sections->{$name} =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $template_sections->{$name} =~ /\S/ 0 2 2
72 2 ▶ return unless $page_sections->{$name} =~ /\S/;
Branch: 1 branch
BranchTrueFalseTotal
unless $page_sections->{$name} =~ /\S/ 0 2 2
73 }
74  
75 1 return 1;
76 }
77  
78 #----------------------------------------------------------------------
79 # Set exclude_index to true in the data package
80  
81 13 ▶sub setup {
Subroutine setup: called CC=1 SCAR=0.0
Pod documented
82 13 my ($self) = @_;
83  
84 13 $self->{data}{exclude_index} = 1;
85 13 return;
86 }
87  
88 #----------------------------------------------------------------------
89 # Find files in directory to convert and do that
90  
91 12 ▶sub update_folder {
Subroutine update_folder: called CC=5 SCAR=16.8
Pod undocumented
92 12 my ($self, $folder) = @_;
93  
94 12 my $index_file = $self->to_file($folder);
95 12 my $base_index_file = $self->to_file($self->{data}{base_directory});
96  
97 12 my $template_file = $self->get_template_name($self->{template_file});
98 12 my $newest_file = $self->{data}->build('newest_file', $base_index_file);
99  
100  
101 12 ▶ unless (fio_is_newer($index_file, $template_file, @$newest_file) &&
Branch: 1 branch
BranchTrueFalseTotal
unless (fio_is_newer($index_file, $template_file, @$newest_file) and $self->sections_are_filled($index_file)) 12 0 12
Condition33%1/3
fio_is_newer($index_file, $template_file, @$newest_file) and $self->sections_are_filled($index_file)
!ll&&!rl&&r
1200
MC/DC0%0/2
fio_is_newer($index_file, $template_file, @$newest_file) and $self->sections_are_filled($index_file)
fio_is_newer($index_file, $template_file, @$newest_file) $self->sections_are_filled($index_file)
Truth table33%1/3
A and B
A= fio_is_newer($index_file, $template_file, @$newest_file)B= $self->sections_are_filled($index_file)
ABresult
0X0
100
111
102 $self->sections_are_filled($index_file)) {
103  
104 12 my $page = $self->render_file($self->{template_file}, $base_index_file);
105  
106 12 my $prototype_file = $self->find_prototype($folder, 0);
107 12 $page = $self->reformat_file($prototype_file, $index_file, $page);
108 12 fio_write_page($index_file, $page);
109 }
110  
111 12 ▶ unless ($self->no_recurse) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->no_recurse) 8 4 12
112 8 my $folders = $self->{data}->build('folders', $index_file);
113 8 foreach my $subfolder (@$folders) {
114 0 eval {$self->update_folder($subfolder)};
115 0 $self->check_error($@, $subfolder);
116 }
117 }
118  
119 12 return;
120 }
121  
122 3 1;
123 __END__
« lib/App/Followme/ConvertPage.pm ↑ Summary lib/App/Followme.pm »