| 1 | ## | ||
| 2 | # name: Module::Install::Stardoc | ||
| 3 | # abstract: Stardoc Support for Module::Install | ||
| 4 | # author: Ingy döt Net <ingy@cpan.org> | ||
| 5 | # copyright: 2011 | ||
| 6 | # license: perl | ||
| 7 | |||
| 8 | package Module::Install::Stardoc; | ||
| 9 | use 5.008003; | ||
| 10 | use strict; | ||
| 11 | use warnings; | ||
| 12 | |||
| 13 | use Module::Install::Base; | ||
| 14 | use vars qw'@ISA $VERSION'; | ||
| 15 | BEGIN { | ||
| 16 | @ISA = 'Module::Install::Base'; | ||
| 17 | $VERSION = '0.18'; | ||
| 18 | } | ||
| 19 | |||
| 20 | use File::Find; | ||
| 21 | |||
| 22 | my @clean; | ||
| 23 | |||
| 24 | sub stardoc_make_pod { | ||
| 25 | my $self = shift; | ||
| 26 | return unless $self->is_admin; | ||
| 27 | require Stardoc::Convert; | ||
| 28 | eval "use IO::All; 1" or die $@; | ||
| 29 | |||
| 30 | my @pms = @_; | ||
| 31 | |||
| 32 | if (not @pms) { | ||
| 33 | File::Find::find(sub { | ||
| 34 | push @pms, $File::Find::name if /\.pm$/; | ||
| 35 | }, 'lib'); | ||
| 36 | }; | ||
| 37 | for my $pm (@pms) { | ||
| 38 | (my $pod = $pm) =~ s/\.pm$/.pod/ or die; | ||
| 39 | my $doc = Stardoc::Convert->perl_file_to_pod($pm) or next; | ||
| 40 | push @clean, $pod; | ||
| 41 | my $old = -e $pod ? io($pod)->all : ''; | ||
| 42 | if ($doc ne $old) { | ||
| 43 | print "Creating $pod from $pm\n"; | ||
| 44 | io($pod)->print($doc); | ||
| 45 | } | ||
| 46 | } | ||
| 47 | } | ||
| 48 | |||
| 49 | sub stardoc_clean_pod { | ||
| 50 | my $self = shift; | ||
| 51 | return unless $self->is_admin; | ||
| 52 | $self->clean_files(join ' ', @clean); | ||
| 53 | } | ||
| 54 | |||
| 55 | 1; | ||
| 56 | |||
| 57 | =head1 SYNOPSIS | ||
| 58 | |||
| 59 | In Makefile.PL: | ||
| 60 | |||
| 61 | use inc::Module::Install; | ||
| 62 | |||
| 63 | stardoc_make_pod; | ||
| 64 | all_from 'lib/Foo.pm'; | ||
| 65 | stardoc_clean_pod; | ||
| 66 | |||
| 67 | =head1 DESCRIPTION | ||
| 68 | |||
| 69 | The C<stardoc_make_pod> command generates a pod file from every .pm file in | ||
| 70 | your lib/ directory that contains Stardoc documentation. | ||
| 71 | |||
| 72 | The C<stardoc_clean_pod> command tells C<make clean> to remove the generated | ||
| 73 | pod files. | ||
| 74 | |||
| 75 | =cut |