| 1 | package HTML::Links::Localize; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | $HTML::Links::Localize::VERSION = '0.2.9'; | |||||||||||||||||||||||||||||||||||||||||
| 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 5.008; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use HTML::TokeParser; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use File::Find; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use File::Copy; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | # Two utility functions | ||||||||||||||||||||||||||||||||||||||||||
| 13 | sub _is_older | ||||||||||||||||||||||||||||||||||||||||||
| 14 | { | ||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | my $file1 = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_older: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | my $file2 = shift; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | my @stat1 = stat($file1); | |||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | my @stat2 = stat($file2); | |||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | return ($stat1[9] <= $stat2[9]); | |||||||||||||||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||
| 22 | sub _is_newer | ||||||||||||||||||||||||||||||||||||||||||
| 23 | { | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | my $file1 = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_is_newer: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | my $file2 = shift; | |||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | return (! _is_older($file1, $file2)); | |||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | sub new | ||||||||||||||||||||||||||||||||||||||||||
| 30 | { | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | bless $self, $class; | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | 1 | $self->_init(@_); | |||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | sub _set_base_dir | ||||||||||||||||||||||||||||||||||||||||||
| 41 | { | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_base_dir: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | my $base_dir = shift; | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | $base_dir =~ s{/*$}{/}; | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | $self->{'base_dir'} = $base_dir; | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | sub _get_base_dir | ||||||||||||||||||||||||||||||||||||||||||
| 54 | { | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_base_dir: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | 1 | return $self->{'base_dir'}; | |||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | sub _set_dest_dir | ||||||||||||||||||||||||||||||||||||||||||
| 61 | { | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_set_dest_dir: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 1 | my $dest_dir = shift; | |||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 1 | $self->{'dest_dir'} = $dest_dir; | |||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | sub _get_dest_dir | ||||||||||||||||||||||||||||||||||||||||||
| 72 | { | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get_dest_dir: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | return $self->{'dest_dir'}; | |||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | sub _init | ||||||||||||||||||||||||||||||||||||||||||
| 79 | { | ||||||||||||||||||||||||||||||||||||||||||
| 80 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_init: called CC=3 SCAR=11.3
| |||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 1 | ▶ | $self->_set_base_dir($args{'base_dir'} || "."); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'base_dir'} || '.'
MC/DC0%0/1
$args{'base_dir'} || '.'
$args{'base_dir'}
Truth table50%1/2
A
A= $args{'base_dir'}
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | ▶ | $self->_set_dest_dir($args{'dest_dir'} || "./dest"); | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$args{'dest_dir'} || './dest'
MC/DC0%0/1
$args{'dest_dir'} || './dest'
$args{'dest_dir'}
Truth table50%1/2
A
A= $args{'dest_dir'}
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | sub process_content | ||||||||||||||||||||||||||||||||||||||||||
| 92 | { | ||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_content: not called CC=15 SCAR=54.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | my $fh = shift; | |||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | my $out_content = ""; | |||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | my $out = sub { | ||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | $out_content .= join("", @_); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | my $parser = HTML::TokeParser->new($fh); | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | while (my $token = $parser->get_token()) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | my $type = $token->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | ▶ | if ($type eq "E") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | { | ||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $out->($token->[2]); | |||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||
| 111 | elsif ($type eq "C") | ||||||||||||||||||||||||||||||||||||||||||
| 112 | { | ||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $out->($token->[1]); | |||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||
| 115 | elsif ($type eq "T") | ||||||||||||||||||||||||||||||||||||||||||
| 116 | { | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | $out->($token->[1]); | |||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||
| 119 | elsif ($type eq "D") | ||||||||||||||||||||||||||||||||||||||||||
| 120 | { | ||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $out->($token->[1]); | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | elsif ($type eq "PI") | ||||||||||||||||||||||||||||||||||||||||||
| 124 | { | ||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $out->($token->[2]); | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | elsif ($type eq "S") | ||||||||||||||||||||||||||||||||||||||||||
| 128 | { | ||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | my $tag = $token->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my %process_tags = | |||||||||||||||||||||||||||||||||||||||||
| 131 | ( | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 'form' => { 'action' => 1 }, | ||||||||||||||||||||||||||||||||||||||||||
| 133 | 'img' => { 'src' => 1}, | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 'a' => { 'href' => 1}, | ||||||||||||||||||||||||||||||||||||||||||
| 135 | 'link' => { 'href' => 1}, | ||||||||||||||||||||||||||||||||||||||||||
| 136 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | ▶ | if (exists($process_tags{$tag})) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | { | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | my $ret = "<$tag"; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | my $attrseq = $token->[3]; | |||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | my $attr_values = $token->[2]; | |||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my $process_attrs = $process_tags{$tag}; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | foreach my $attr (@$attrseq) | |||||||||||||||||||||||||||||||||||||||||
| 144 | { | ||||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $value = $attr_values->{$attr}; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | ▶ | if (exists($process_attrs->{$attr})) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | { | ||||||||||||||||||||||||||||||||||||||||||
| 148 | # If it's a local link that ends with slash - | ||||||||||||||||||||||||||||||||||||||||||
| 149 | # then append index.html | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if (($value !~ /^[a-z]+:/) && ($value !~ /^\//) && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
not $value =~ /^[a-z]+:/ || $value =~ m[^/] and $value =~ m[/(#[^#/]*)?$]
$value =~ /^[a-z]+:/ || $value =~ m[^/]
MC/DC0%0/3
not $value =~ /^[a-z]+:/ || $value =~ m[^/] and $value =~ m[/(#[^#/]*)?$]
$value =~ /^[a-z]+:/
$value =~ m[^/]
$value =~ m[/(#[^#/]*)?$]
Truth table0%0/4
not(A || B) and C
A= $value =~ /^[a-z]+:/B= $value =~ m[^/]C= $value =~ m[/(#[^#/]*)?$]
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | ($value =~ /\/(#[^#\/]*)?$/)) | ||||||||||||||||||||||||||||||||||||||||||
| 152 | { | ||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | my $pos = rindex($value, "/"); | |||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | substr($value,$pos+1,0) = "index.html"; | |||||||||||||||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 0 | ▶ | if ($attr eq "/") | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 158 | { | ||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | $ret .= " /"; | |||||||||||||||||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||||||||||||||||
| 161 | else | ||||||||||||||||||||||||||||||||||||||||||
| 162 | { | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $ret .= " $attr=\"$value\""; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | $out->($ret); | |||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | $out->(">"); | |||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||
| 169 | else | ||||||||||||||||||||||||||||||||||||||||||
| 170 | { | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | $out->($token->[4]); | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | return $out_content; | |||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||
| 179 | sub process_file | ||||||||||||||||||||||||||||||||||||||||||
| 180 | { | ||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_file: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | my $filename = shift; | |||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | my $dest_dir = $self->_get_dest_dir(); | |||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | my $src_dir = $self->_get_base_dir(); | |||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | open my $in, '<', "$src_dir/$filename" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | or die "Cannot open '$src_dir/$filename' - $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | open my $out, '>', "$dest_dir/$filename" | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | or die "Cannot open '$dest_dir/$filename' for writing- $!"; | ||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | print {$out} $self->process_content($in); | |||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | close($in); | |||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | close($out); | |||||||||||||||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||||||||||||||||
| 196 | sub process_dir_tree | ||||||||||||||||||||||||||||||||||||||||||
| 197 | { | ||||||||||||||||||||||||||||||||||||||||||
| 198 | 1 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process_dir_tree: called CC=6 SCAR=26.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | 1 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||
| 202 | my $should_replace_file = sub { | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | ▶ | my ($src, $dest) = @_; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | ▶ | if ($args{'only-newer'}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 205 | { | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | ▶ | return ((! -e $dest) || (_is_newer($src, $dest))); | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
!(-e $dest) || _is_newer($src, $dest)
MC/DC0%0/2
!(-e $dest) || _is_newer($src, $dest)
!(-e $dest)
_is_newer($src, $dest)
Truth table0%0/3
not(A) || B
A= !(-e $dest)B= _is_newer($src, $dest)
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | else | ||||||||||||||||||||||||||||||||||||||||||
| 209 | { | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 1 | my $src_dir = $self->_get_base_dir(); | |||||||||||||||||||||||||||||||||||||||||
| 215 | 1 | my $dest_dir = $self->_get_dest_dir(); | |||||||||||||||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | my (@dirs, @other_files, @html_files); | |||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | my $wanted = sub { | ||||||||||||||||||||||||||||||||||||||||||
| 220 | 1 | ▶ | my $filename = $File::Find::name; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=22.9
| |||||||||||||||||||||||||||||||||||||||||||
| 221 | 1 | ▶ | if (length($filename) < length($src_dir)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 222 | { | ||||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||
| 225 | # Remove the $src_dir from the filename; | ||||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | $filename = substr($filename, length($src_dir)); | |||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | if (-d $_) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | { | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | push @dirs, $filename; | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | elsif (/\.html?$/) | ||||||||||||||||||||||||||||||||||||||||||
| 233 | { | ||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | push @html_files, $filename; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | else | ||||||||||||||||||||||||||||||||||||||||||
| 237 | { | ||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | push @other_files, $filename; | |||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | 1 | find($wanted, $src_dir); | |||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||
| 244 | my $soft_mkdir = sub { | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 1 | ▶ | my $dir = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 246 | 1 | ▶ | if (-d $dir) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | { | ||||||||||||||||||||||||||||||||||||||||||
| 248 | # Do nothing | ||||||||||||||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||||||||||||||
| 250 | elsif (-e $dir) | ||||||||||||||||||||||||||||||||||||||||||
| 251 | { | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | die "$dir exists in destination and is not a directory"; | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | else | ||||||||||||||||||||||||||||||||||||||||||
| 255 | { | ||||||||||||||||||||||||||||||||||||||||||
| 256 | 1 | ▶ | mkdir($dir) || die "mkdir failed: $!\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | } | ||||||||||||||||||||||||||||||||||||||||||
| 258 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | # Create the directory structure in $dest | ||||||||||||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||||||||||
| 262 | 1 | $soft_mkdir->($dest_dir); | |||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | foreach my $dir (@dirs) | |||||||||||||||||||||||||||||||||||||||||
| 264 | { | ||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | $soft_mkdir->("$dest_dir/$dir"); | |||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | foreach my $file (@other_files) | |||||||||||||||||||||||||||||||||||||||||
| 269 | { | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | my $src = "$src_dir/$file"; | |||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | my $dest = "$dest_dir/$file"; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if ($should_replace_file->($src, $dest)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | { | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | copy($src, $dest); | |||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||
| 278 | 1 | foreach my $file (@html_files) | |||||||||||||||||||||||||||||||||||||||||
| 279 | { | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | my $src = "$src_dir/$file"; | |||||||||||||||||||||||||||||||||||||||||
| 281 | 0 | my $dest = "$dest_dir/$file"; | |||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | ▶ | if ($should_replace_file->($src,$dest)) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 283 | { | ||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | $self->process_file($file); | |||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||
| 291 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||
| 293 | __END__ | ||||||||||||||||||||||||||||||||||||||||||