SiteTear/CSS.pm

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