| 1 | package App::Followme::ConvertPage; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use 5.008005; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use lib '../..'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use base qw(App::Followme::Module); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use File::Spec::Functions qw(abs2rel rel2abs catfile splitdir); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use App::Followme::FIO; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 2 | our $VERSION = "2.03"; | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 16 | # Read the default parameter values | ||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 24 | ▶ | sub parameters { | ||||||||||||||||||||||||||
|
Subroutine
parameters: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 19 | 24 | my ($pkg) = @_; | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | return ( | ||||||||||||||||||||||||||||
| 22 | 24 | template_file => 'convert_page.htm', | |||||||||||||||||||||||||||
| 23 | data_pkg => 'App::Followme::TextData', | ||||||||||||||||||||||||||||
| 24 | ); | ||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 28 | # Convert files to html | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 5 | ▶ | sub run { | ||||||||||||||||||||||||||
|
Subroutine
run: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | 5 | my ($self, $folder) = @_; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 5 | $self->update_folder($folder); | |||||||||||||||||||||||||||
| 34 | 5 | return; | |||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 38 | # Set the date format to iso date format, overriding user | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 6 | ▶ | sub setup { | ||||||||||||||||||||||||||
|
Subroutine
setup: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 41 | 6 | my ($self) = @_; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 6 | $self->{data}{date_format} = 'yyyy-mm-ddThh:mm:ss'; | |||||||||||||||||||||||||||
| 44 | 6 | return; | |||||||||||||||||||||||||||
| 45 | } | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 48 | # Construct a filename that represents the title | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 13 | ▶ | sub title_to_filename { | ||||||||||||||||||||||||||
|
Subroutine
title_to_filename: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 51 | 13 | my ($self, $filename) = @_; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 13 | my ($dir, $base) = fio_split_filename($filename); | |||||||||||||||||||||||||||
| 54 | 13 | ▶ | return $filename if $base =~ /^index\./; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 9 | my @parts = split(/\./, $base); | |||||||||||||||||||||||||||
| 57 | 9 | my $ext = pop(@parts); | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 9 | my $new_filename = ${$self->{data}->build('title', $filename)}; | |||||||||||||||||||||||||||
| 60 | 9 | ▶ | return $filename unless $new_filename; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 9 | $new_filename = lc($new_filename); | |||||||||||||||||||||||||||
| 63 | 9 | $new_filename =~ s/[^\w\-\_]+/ /g; | |||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 9 | $new_filename =~ s/^ +//; | |||||||||||||||||||||||||||
| 66 | 9 | $new_filename =~ s/ +$//; | |||||||||||||||||||||||||||
| 67 | 9 | $new_filename =~ s/ +/\-/g; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 9 | $new_filename = catfile($dir, join('.', $new_filename, $ext)); | |||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||
| 71 | 9 | return $new_filename; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 75 | # Convert a single file | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | 12 | ▶ | sub update_file { | ||||||||||||||||||||||||||
|
Subroutine
update_file: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 78 | 12 | my ($self, $folder, $prototype, $file) = @_; | |||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||
| 80 | 12 | my $new_file = $self->{data}->convert_filename($file); | |||||||||||||||||||||||||||
| 81 | 12 | my $page = $self->render_file($self->{template_file}, $file); | |||||||||||||||||||||||||||
| 82 | 12 | $page = $self->reformat_file($prototype, $new_file, $page); | |||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 12 | $self->write_file($new_file, $page); | |||||||||||||||||||||||||||
| 85 | 12 | return; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 89 | # Find files in directory to convert and do that | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 9 | ▶ | sub update_folder { | ||||||||||||||||||||||||||
|
Subroutine
update_folder: called CC=7 SCAR=19.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 92 | 9 | my ($self, $folder) = @_; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 9 | my $index_file = $self->to_file($folder); | |||||||||||||||||||||||||||
| 95 | 9 | my $source_folder = $self->{data}->convert_source_directory($folder); | |||||||||||||||||||||||||||
| 96 | 9 | ▶ | return unless $source_folder; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | my $same_directory = fio_same_file($folder, $source_folder, | ||||||||||||||||||||||||||||
| 99 | 9 | $self->{case_sensitivity}); | |||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | 9 | $index_file = $self->to_file($source_folder); | |||||||||||||||||||||||||||
| 102 | 9 | my $files = $self->{data}->build('files', $index_file); | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 9 | my $prototype; | |||||||||||||||||||||||||||
| 105 | 9 | foreach my $file (@$files) { | |||||||||||||||||||||||||||
| 106 | 11 | ▶ | my $prototype ||= $self->find_prototype($folder, 0); | ||||||||||||||||||||||||||
|
Condition33%1/3
my $prototype ||= $self->find_prototype($folder, 0)
MC/DC0%0/2
my $prototype ||= $self->find_prototype($folder, 0)
my $prototype
$self->find_prototype($folder, 0)
Truth table33%1/3
A ||= B
A= my $prototypeB= $self->find_prototype($folder, 0)
| |||||||||||||||||||||||||||||
| 107 | 11 | eval {$self->update_file($folder, $prototype, $file)}; | |||||||||||||||||||||||||||
| 108 | 11 | ▶ | if ($self->check_error($@, $file)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | 11 | ▶ | unlink($file) if $same_directory; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||
| 113 | 9 | my $folders = $self->{data}->build('folders', $index_file); | |||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 9 | foreach my $subfolder (@$folders) { | |||||||||||||||||||||||||||
| 116 | 3 | $self->update_folder($subfolder); | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||
| 119 | 9 | return; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||
| 123 | # Write a file, setting folder level metadata | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 12 | ▶ | sub write_file { | ||||||||||||||||||||||||||
|
Subroutine
write_file: called CC=3 SCAR=11.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 126 | 12 | my ($self, $filename, $page, $binmode) = @_; | |||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 12 | my $time = ${$self->{data}->build('mdate', $filename)}; | |||||||||||||||||||||||||||
| 129 | 12 | my $new_filename = $self->title_to_filename($filename); | |||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||
| 131 | 12 | fio_write_page($new_filename, $page, $binmode); | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | unlink($filename) if -e $filename && | ||||||||||||||||||||||||||||
| 134 | 12 | ▶ | ! fio_same_file($filename, $new_filename, $self->{case_sensitivity}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
-e $filename and not fio_same_file($filename, $new_filename, $self->{"case_sensitivity"})
MC/DC0%0/2
-e $filename and not fio_same_file($filename, $new_filename, $self->{"case_sensitivity"})
-e $filename
not fio_same_file($filename, $new_filename, $self->{"case_sensitivity"})
Truth table33%1/3
A and not(B)
A= -e $filenameB= not fio_same_file($filename, $new_filename, $self->{"case_sensitivity"})
| |||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 12 | fio_set_date($new_filename, $time); | |||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | 12 | return; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 2 | 1; | |||||||||||||||||||||||||||
| 142 | __END__ | ||||||||||||||||||||||||||||