| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 72 | 2 | ▶ | return unless $page_sections->{$name} =~ /\S/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
Condition33%1/3
fio_is_newer($index_file, $template_file, @$newest_file) and $self->sections_are_filled($index_file)
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)
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||