File Coverage

blib/lib/Pod/ProjectDocs/Doc.pm
Criterion Covered Total %
statement 64 70 91.4
branch 5 12 41.6
condition 5 9 55.5
subroutine 14 15 93.3
pod 0 4 0.0
total 88 110 80.0


line stmt bran cond sub pod time code
1             package Pod::ProjectDocs::Doc;
2              
3 4     4   29 use strict;
  4         11  
  4         125  
4 4     4   21 use warnings;
  4         7  
  4         155  
5              
6             our $VERSION = '0.53'; # VERSION
7              
8 4     4   43 use Moose;
  4         9  
  4         24  
9             with 'Pod::ProjectDocs::File';
10              
11 4     4   24377 use File::Basename;
  4         8  
  4         264  
12 4     4   26 use File::Spec;
  4         8  
  4         116  
13 4     4   2132 use File::Copy;
  4         9214  
  4         215  
14 4     4   27 use Carp();
  4         10  
  4         2605  
15              
16             has 'origin' => (
17             is => 'rw',
18             isa => 'Str',
19             );
20              
21             has 'suffix' => (
22             is => 'rw',
23             isa => 'Str',
24             );
25              
26             has 'origin_root' => (
27             is => 'rw',
28             isa => 'Str',
29             );
30              
31             has 'title' => (
32             is => 'rw',
33             isa => 'Str',
34             );
35              
36             has 'data' => (
37             is => 'ro',
38             default => <<'DATA',
39             <div class="box">
40             <h1 class="t1">[% title | html %]</h1>
41             <table>
42             <tr>
43             <td class="label">Description</td>
44             <td class="cell">[% desc | html | html_line_break %]</td>
45             </tr>
46             </table>
47             </div>
48             <div class="path">
49             <a href="[% outroot _ '/index.html' | relpath %]">[% title | html %]</a> &gt; [% mgr_desc | html %] &gt;
50             [% name | html %]
51             </div>
52             <div>
53             [% IF !nosourcecode %]
54             <a href="[% src | relpath %]">Source</a>
55             [% END %]
56             </div>
57             DATA
58             );
59              
60             sub BUILD {
61 5     5 0 11797 my $self = shift;
62              
63             # This must be done after the other data is available.
64 5         16 $self->_set_relpath;
65 5         14 return;
66             }
67              
68             sub _set_relpath {
69 5     5   10 my $self = shift;
70 5         150 my $suffix = $self->suffix;
71 5         121 my ( $name, $dir ) = fileparse $self->origin, qr/\.$suffix/;
72 5         159 my $reldir = File::Spec->abs2rel( $dir, $self->origin_root );
73 5   33     17 $reldir ||= File::Spec->curdir;
74 5         138 my $outroot = $self->config->outroot;
75 5         18 $self->_check_dir( $reldir, $outroot );
76 5         42 $self->_check_dir( $reldir, File::Spec->catdir( $outroot, "src" ) );
77 5         36 my $relpath = File::Spec->catdir( $reldir, $name );
78 5 50       23 $relpath =~ s:\\:/:g if $^O eq 'MSWin32';
79              
80 5 50 66     40 if ( lc $suffix eq 'pm' || lc $suffix eq 'pod' ) {
81 5         186 $self->name( join "::", File::Spec->splitdir($relpath) );
82             }
83             else {
84 0         0 $self->name( join "/", File::Spec->splitdir($relpath) );
85             }
86 5         155 $self->relpath( $relpath . "." . $suffix . ".html" );
87 5         13 return;
88             }
89              
90             sub _check_dir {
91 10     10   24 my ( $self, $dir, $path ) = @_;
92 10         26 $self->_mkdir($path);
93 10         53 my @dirs = File::Spec->splitdir($dir);
94 10         24 foreach my $dir (@dirs) {
95 10         65 $path = File::Spec->catdir( $path, $dir );
96 10         38 $self->_mkdir($path);
97             }
98 10         24 return;
99             }
100              
101             sub _mkdir {
102 20     20   37 my ( $self, $path ) = @_;
103 20 100 66     462 unless ( -e $path && -d _ ) {
104 10 50       601 mkdir( $path, 0755 )
105             or Carp::croak(qq/Can't make directory [$path]./);
106             }
107 20         74 return;
108             }
109              
110             sub get_output_src_path {
111 9     9 0 20 my $self = shift;
112 9         211 my $outroot = File::Spec->catdir( $self->config->outroot, "src" );
113 9         255 my $relpath = $self->relpath;
114 9         234 my $suffix = $self->suffix;
115 9         53 $relpath =~ s/\.html$//;
116 9         79 my $path = File::Spec->catfile( $outroot, $relpath );
117 9         141 return $path;
118             }
119              
120             sub copy_src {
121 4     4 0 9 my $self = shift;
122 4         119 my $origin = $self->origin;
123 4         15 my $newsrc = $self->get_output_src_path;
124 4         27 File::Copy::copy( $origin, $newsrc );
125 4         1734 return;
126             }
127              
128             sub is_modified {
129 0     0 0   my $self = shift;
130 0           my $origin = $self->origin;
131 0           my $newsrc = $self->get_output_src_path;
132 0 0         return 1 unless ( -e $newsrc );
133 0 0         return ( -M $origin < -M $newsrc ) ? 1 : 0;
134             }
135              
136 4     4   50 no Moose;
  4         9  
  4         39  
137              
138             1;