DocSet/Doc/Common.pm untested

filter: Statementstmt 0.0% 0 / 64 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 92 CC 6 SCAR 18.2
CC
6
Cov
0%
pod_pom_html_view_seq_link_transform_path
12.0
fetch_pdf_doc_ver
6.0
fetch_src_doc_ver
6.0
CRAP 6.2
1 package DocSet::Doc::Common;
2  
3 use File::Spec::Functions;
4 use DocSet::Util;
5 use DocSet::RunTime;
6  
7 # See HTML2HTMLPS.pm or POD2HTMLPS.pm
8 sub postprocess_ps_pdf {
9 my $self = shift;
10  
11 # convert to ps
12 my $html2ps_exec = DocSet::RunTime::can_create_ps();
13 my $html2ps_conf = $self->{docset}->get_file('html2ps_conf');
14 my $dst_path = $self->{dst_path};
15  
16 (my $dst_base = $dst_path) =~ s/\.html//;
17  
18 my $dst_root = $self->{dst_root};
19 my $command = "$html2ps_exec -f $html2ps_conf -o ${dst_base}.ps ${dst_base}.html";
20 note "% $command";
21 system $command;
22  
23 # convert to pdf
24 $command = "ps2pdf ${dst_base}.ps ${dst_base}.pdf";
25 note "% $command";
26 system $command;
27  
28 # META: can delete the .ps now
29  
30 }
31  
32  
33  
34 # search for a pdf version in the parallel tree and copy/gzip it to
35 # the same dir as the html version (we link to it from the html)
36 sub fetch_pdf_doc_ver {
37 my $self = shift;
38  
39 my $dst_path = $self->{dst_path};
40 $dst_path =~ s/html$/pdf/;
41  
42 my $pdf_path = $dst_path;
43  
44 my $docset = $self->{docset};
45 my $ps_root = $docset->get_dir('dst_ps');
46 my $html_root = $docset->get_dir('dst_html');
47  
48 $pdf_path =~ s/^$html_root/$ps_root/;
49  
50 #print "TRYING $dst_path $pdf_path \n";
51  
52 my %pdf = ();
53 # if in the pdf tree (rel_pdf) there is nothing to copy
54 if (-e $pdf_path && $pdf_path ne $dst_path) {
55 copy_file($pdf_path, $dst_path);
56 %pdf = (
57 size => format_bytes(-s $dst_path),
58 link => filename($dst_path),
59 );
60 # gzip_file($dst_path);
61 # my $gzip_path = "$dst_path.gz";
62 # %pdf = (
63 # size => format_bytes(-s $gzip_path),
64 # link => filename($gzip_path),
65 # );
66 }
67 #dumper \%pdf;
68  
69 return \%pdf;
70  
71 }
72  
73 # search for the source version in the source tree and copy/gzip it to
74 # the same dir as the html version (we link to it from the html)
75 sub fetch_src_doc_ver {
76 my $self = shift;
77 #$self->src_uri
78  
79 my $dst_path = catfile $self->{dst_root}, $self->{src_uri};
80 my $src_path = catfile $self->{src_root}, $self->{src_uri};
81  
82 # the source file may have the same extension as the dest file, so
83 # add a new extension. This will also be useful for doing patches.
84 $dst_path .= ".orig";
85  
86 #print "TRYING $dst_path $src_path \n";
87  
88 my %src = ();
89 if (-e $src_path) {
90 copy_file($src_path, $dst_path);
91 %src = (
92 size => format_bytes(-s $dst_path),
93 link => filename($dst_path),
94 );
95 # gzip_file($dst_path);
96 # my $gzip_path = "$dst_path.gz";
97 # %src = (
98 # size => format_bytes(-s $gzip_path),
99 # link => filename($gzip_path),
100 # );
101 }
102 #dumper \%src;
103  
104 return \%src;
105 }
106  
107 sub pod_pom_html_view_seq_link_transform_path {
108 my ($self, $path) = @_;
109  
110 $path =~ s|::|/|g;
111 my $doc_obj = get_render_obj();
112  
113 my $res_path = $doc_obj->transform_src_doc($path);
114 unless ($res_path) {
115 # report broken links if we were told to
116 if (DocSet::RunTime::get_opts('validate_links')) {
117 print "!!! Broken link $doc_obj->{src_path}: [$path]\n";
118 }
119 return undef;
120 }
121  
122 $res_path =~ s/\.[^.]+$/.html/;
123 # print "$res_path\n";
124 return $res_path;
125 }
126  
127  
128 #sub make_href {
129 # my ($url, $title) = @_;
130  
131 # if (!defined $url) {
132 # return defined $title ? "<i>$title</i>" : '';
133 # }
134  
135 # $title = $url unless defined $title;
136 #print "$url, $title\n";
137 # return qq{<a href="$url">$title</a>};
138 #}
139  
140 sub pod_pom_html_anchor {
141 my ($self, $title) = @_;
142 my $anchor = "$title";
143 $anchor =~ s/^\s*|\s*$//g; # strip leading and closing spaces
144 $anchor =~ s/\W/_/g;
145 my $link = $title->present($self);
146  
147 # die on duplicated anchors
148 my $render_obj = get_render_obj();
149 $render_obj->{__seen_anchors}{$anchor}++;
150 $render_obj->croak("a duplicated anchor: '$anchor'\nfor title: '$title'\n")
151 if $render_obj->{__seen_anchors}{$anchor} > 1;
152  
153 return qq{<a name="$anchor"></a><a href="#toc_$anchor">$link</a>};
154 }
155  
156  
157  
158  
159  
160 1;
161 __END__