« blib/lib/App/RecordStream/DBHandle.pm
↑ Summary
blib/lib/App/RecordStream/Operation/toprettyprint.pm »
| 1 | use strict; | ||
| 2 | use warnings; | ||
| 3 | |||
| 4 | package App::RecordStream::Operation::help::FromManual; | ||
| 5 | use base qw(App::RecordStream::Operation::help); | ||
| 6 | |||
| 7 | use Pod::Perldoc; | ||
| 8 | use File::Temp qw< tempfile >; | ||
| 9 | use Scalar::Util qw< blessed >; | ||
| 10 | |||
| 11 | sub init_help {} | ||
| 12 | sub init { | ||
| 13 | my $this = shift; | ||
| 14 | local @ARGV = ('-F', $this->pod_file); | ||
| 15 | Pod::Perldoc->run(); | ||
| 16 | } | ||
| 17 | |||
| 18 | sub pod_file { | ||
| 19 | my $this = shift; | ||
| 20 | my ($class, $pm) = $this->manual_class; | ||
| 21 | my $source = $INC{$pm}; | ||
| 22 | |||
| 23 | # Simple case: manual class is on disk already | ||
| 24 | if (not ref $source and -e $source) { | ||
| 25 | return $source; | ||
| 26 | } | ||
| 27 | # Fatpacked: read from the @INC hook | ||
| 28 | elsif (ref $source and blessed($source) =~ /^FatPacked::/) { | ||
| 29 | my $source_fh = $source->INC($pm) | ||
| 30 | or die "FatPacked INC entry failed?!"; | ||
| 31 | |||
| 32 | my ($tmp, $tmpfile) = tempfile( UNLINK => 1, TMPDIR => 1, SUFFIX => '.pm' ); | ||
| 33 | print { $tmp } $_ while <$source_fh>; | ||
| 34 | close $tmp | ||
| 35 | or die "failed to close tempfile $tmpfile after writing: $!"; | ||
| 36 | return $tmpfile; | ||
| 37 | } | ||
| 38 | else { | ||
| 39 | die "Don't know how to read source of $class where \$INC{$pm} = $source"; | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | sub manual_class { | ||
| 44 | my $this = shift; | ||
| 45 | my $page = (split /::/, ref $this)[-1]; | ||
| 46 | my $class = "App::RecordStream::Manual::\u$page"; | ||
| 47 | my $pm = "$class.pm"; | ||
| 48 | $pm =~ s{::}{/}g; | ||
| 49 | require $pm | ||
| 50 | or die "Can't locate manual class $class: $!"; | ||
| 51 | return wantarray ? ($class, $pm) : $class; | ||
| 52 | } | ||
| 53 | |||
| 54 | 1; |