SiteTear/CSS.pm

filter: Statementstmt 35.7% 20 / 56 Branchbran 0.0% 0 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 66.6% 6 / 9 Podpod 100% 3 / 3 totaltotal 35.3% 29 / 82 CC 8 SCAR 25.5
CC
8
Cov
29%
copy_to_linkpath
30.0
css_copy
12.0
new
6.0
CRAP 12.8
« SiteTear/Page.pm ↑ Summary SiteTear/Root.pm »
1 package HTML::SiteTear::CSS;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use File::Path;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use base qw(HTML::SiteTear::Item);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 our $VERSION = '1.45';
11  
12 =head1 NAME
13  
14 HTML::SiteTear::CSS - treat cascading style sheet files.
15  
16 =head1 SYMPOSIS
17  
18 use HTML::SiteTear::CSS;
19
20 $item = HTML::SiteTear::CSS->new($parent,$source_path,$kind);
21 $item->linkpath($path); # usually called from the mothod "change_path"
22 # of the parent object.
23 $item->copy_to_linkpath();
24 $item->copy_linked_files();
25  
26 =head1 DESCRIPTION
27  
28 This module is to treat cascading style sheet files liked from web pages. It's also a sub class of the L<HTML::SiteTear::Item>. Internal use only.
29  
30 =head1 METHODS
31  
32 =head2 new
33  
34 $css = HTML::SiteTear::CSS->new('parent' => $parent,
35 'source_path' => $source_path);
36  
37 Make an instance of this moduel. The parent object "$parent" must be an instance of HTML::SiteTear::Page. This method is called from $parent.
38  
39 =cut
40  
41 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
42 0 my $class = shift @_;
43 0 my $self = $class->SUPER::new(@_);
44 0 ▶ unless ($self->kind ) { $self->kind('css') };
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->kind) 0 0 0
45 0 $self->{'linkedFiles'} = [];
46 0 return $self;
47 }
48  
49 =head2 css_copy
50  
51 $css->css_copy($source_path, $target_path);
52  
53 Copy a cascading style sheet file "$source_path" into $target_path dealing with internal links. This method is called form the method "copy_to_linkpath".
54  
55 =cut
56  
57 0 ▶sub css_copy {
Subroutine css_copy: not called CC=3 SCAR=24.8
Pod documented
58 0 my ($self, $target_path) = @_;
59 0 my $source_path = $self->source_path;
60 0 open(my $CSSIN, "< $source_path");
61 0 open(my $CSSOUT, "> $target_path");
62 0 ▶ while (my $a_line = <$CSSIN>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $a_line = readline $CSSIN)) 0 0 0
63 0 ▶ if ($a_line =~ /url\(([^()]+)\)/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($a_line =~ /url\(([^()]+)\)/) 0 0 0
64 0 my $new_link = $self->change_path($1, $self->resource_folder_name, 'css');
65 0 $a_line =~ s/url\([^()]+\)/url\($new_link\)/;
66 }
67 0 print $CSSOUT $a_line;
68 }
69 0 close($CSSIN);
70 0 close($CSSOUT);
71 }
72  
73 =head2 copy_to_linkpath
74  
75 $item->copy_to_linkpath;
76  
77 Copy $source_path into new linked path from $parent.
78  
79 =cut
80  
81 0 ▶sub copy_to_linkpath {
Subroutine copy_to_linkpath: not called CC=5 SCAR=34.0
Pod documented
82 0 my ($self) = @_;
83 0 my $source_path = $self->source_path;
84 0 ▶ unless ($self->exists_in_copied_files($source_path)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->exists_in_copied_files($source_path)) 0 0 0
85 0 ▶ unless (-e $source_path) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $source_path) 0 0 0
86 0 die("The file \"$source_path\" does not exists.\n");
87 0 return;
88 }
89
90 0 my $target_path = do {
91 0 ▶ if (my $target_uri = $self->item_in_filemap($source_path)) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $target_uri = $self->item_in_filemap($source_path)) { } 0 0 0
92 0 $target_uri->file;
93 } else {
94 0 $self->link_uri->file;
95 }};
96  
97 0 print "Copying asset...\n";
98 0 print "from : $source_path\n";
99 0 print "to : $target_path\n\n";
100 0 ▶ ($source_path eq $target_path) and die "source and target is same file.\n";
Branch: 1 branch
BranchTrueFalseTotal
$source_path eq $target_path and die "source and target is same file.\n" 0 0 0
101 0 mkpath(dirname($target_path));
102 0 $self->target_path($target_path); #temporary set for css_copy
103 0 $self->css_copy($target_path);
104 0 $self->add_to_copyied_files($source_path);
105 0 $self->copy_linked_files;
106 }
107 }
108  
109 =head1 SEE ALSO
110  
111 L<HTML::SiteTear>, L<HTML::SiteTear::Page>, L<HTML::SiteTear::CSS>, L<HTML::SiteTear::Root>
112  
113 =head1 AUTHOR
114  
115 Tetsuro KURITA <tkurita@mac.com>
116  
117 =cut
118  
119 1 1;
« SiteTear/Page.pm ↑ Summary SiteTear/Root.pm »