1package Pod::ProjectDocs::Doc; 2use strict; 3use warnings; 4use base qw/Pod::ProjectDocs::File/; 5use File::Basename; 6use File::Spec; 7use File::Copy; 8 9__PACKAGE__->mk_accessors(qw/origin suffix origin_root title/); 10__PACKAGE__->data( do{ local $/; <DATA> } ); 11 12sub _init { 13 my($self, %args) = @_; 14 $self->SUPER::_init(%args); 15 $self->origin( $args{origin} ); 16 $self->origin_root( $args{origin_root} ); 17 $self->suffix( $args{suffix} ); 18 $self->_set_relpath; 19} 20 21sub _set_relpath { 22 my $self = shift; 23 my $suffix = $self->suffix; 24 my($name, $dir) = fileparse $self->origin, qr/\.$suffix/; 25 my $reldir = File::Spec->abs2rel($dir, $self->origin_root); 26 $reldir ||= File::Spec->curdir; 27 my $outroot = $self->config->outroot; 28 $self->_check_dir($reldir, $outroot); 29 $self->_check_dir($reldir, File::Spec->catdir($outroot, "src")); 30 my $relpath = File::Spec->catdir($reldir, $name); 31 $relpath =~ s:\\:/:g if $^O eq 'MSWin32'; 32 $self->name( join "-", File::Spec->splitdir($relpath) ); 33 $self->relpath($relpath.".".$suffix.".html"); 34} 35 36sub _check_dir { 37 my($self, $dir, $path) = @_; 38 $self->_mkdir($path); 39 my @dirs = File::Spec->splitdir($dir); 40 foreach my $dir (@dirs) { 41 $path = File::Spec->catdir($path, $dir); 42 $self->_mkdir($path); 43 } 44} 45 46sub _mkdir { 47 my($self, $path) = @_; 48 unless(-e $path && -d _) { 49 mkdir($path, 0755) 50 or $self->_croak(qq/Can't make directory [$path]./); 51 } 52} 53 54sub get_output_src_path { 55 my $self = shift; 56 my $outroot = File::Spec->catdir($self->config->outroot, "src"); 57 my $relpath = $self->relpath; 58 my $suffix = $self->suffix; 59 $relpath =~ s/\.html$//; 60 my $path = File::Spec->catfile($outroot, $relpath); 61 return $path; 62} 63 64sub copy_src { 65 my $self = shift; 66 my $origin = $self->origin; 67 my $newsrc = $self->get_output_src_path; 68 File::Copy::copy($origin, $newsrc); 69} 70 71sub is_modified { 72 my $self = shift; 73 my $origin = $self->origin; 74 my $newsrc = $self->get_output_src_path; 75 return 1 unless( -e $newsrc ); 76 return (-M $origin < -M $newsrc) ? 1 : 0; 77} 78 791; 80__DATA__ 81<div class="box"> 82 <h1 class="t1">[% title | html %]</h1> 83 <table> 84 <tr> 85 <td class="label">Description</td> 86 <td class="cell">[% desc | html | html_line_break %]</td> 87 </tr> 88 </table> 89</div> 90<div class="path"> 91 <a href="[% outroot _ '/index.html' | relpath %]">[% title | html %]</a> > [% mgr_desc | html %] > 92 [% name | html %] 93</div> 94<div> 95<a href="[% src | relpath %]">Source</a> 96</div> 97 98 99