/[Frey]/branches/no-pager/lib/Frey/Pod.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /branches/no-pager/lib/Frey/Pod.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 271 - (hide annotations)
Wed Nov 5 08:20:45 2008 UTC (15 years, 5 months ago) by dpavlin
Original Path: trunk/lib/Frey/Pod.pm
File size: 1270 byte(s)
 r3091@llin (orig r237):  dpavlin | 2008-11-01 17:42:17 +0100
 better report errors

1 dpavlin 126 package Frey::Pod;
2     use Moose;
3    
4     =head1 NAME
5    
6     Frey::Pod - display documentation
7    
8     =cut
9    
10     extends 'Frey::ClassLoader';
11     with 'Frey::Web';
12    
13     has 'class' => (
14     is => 'rw',
15     isa => 'Str',
16     required => 1,
17     );
18    
19     use File::Slurp;
20     use Data::Dump qw/dump/;
21    
22 dpavlin 213 sub request {
23 dpavlin 126 my ( $self, $req ) = @_;
24     my $f = { $req->params };
25     my $class = delete( $f->{class} ) || $self->class;
26     $req->print( $self->page( title => $class, body => $self->markup( $class ) ) );
27     }
28    
29     sub markup {
30 dpavlin 178 my $self = shift;
31     my $class = $self->class;
32 dpavlin 126 use Pod::Simple::HTML;
33 dpavlin 128 my $path = eval { $self->package_path( $class ) };
34 dpavlin 271 if ( $@ ) {
35     warn $@;
36     return;
37     }
38 dpavlin 128 my $pod = read_file( $path );
39 dpavlin 126 my $converter = Pod::Simple::HTML->new();
40     my $body;
41     my $my_classes = join('|', $self->classes);
42     $converter->output_string( \$body );
43     $converter->parse_string_document($pod);
44     $body =~ s{.*?<body [^>]+>}{}s;
45     $body =~ s{</body>\s*</html>\s*$}{};
46 dpavlin 130 $body =~ s!%3A%3A!::!g;
47 dpavlin 138 $body =~ s{<a href="http://search\.cpan\.org/perldoc\?($my_classes)"([^>]*)>}{<a href="/~/$1"$2>}g;
48 dpavlin 210 $body =~ s{<a href="http://(search\.cpan\.org)/([^"]+)"([^>]*)>}{<a target="$1" href="http://$1/$2"$3>}g;
49 dpavlin 126 $body =~ s!</li>\n\t<ul>!<ul>!;
50     $body =~ s!</ul>!</ul></li>!;
51     $body =~ s!<p></p>!!;
52     $body =~ s!__index__!index!g;
53 dpavlin 128 return $body;
54 dpavlin 126 }
55    
56     1;
57    

  ViewVC Help
Powered by ViewVC 1.1.26