Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: oalders/Pod2HTML
base: 80d81d5ce1
...
head fork: oalders/Pod2HTML
compare: 2e6a63bda5
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 4 files changed
  • 0 commit comments
  • 1 contributor
View
18 lib/MetaCPAN/Pod.pm
@@ -4,7 +4,6 @@ use Moose;
use Archive::Tar;
use CHI;
-use Data::Dump qw( dump );
use Furl;
use JSON;
use MetaCPAN::Pod::XHTML;
@@ -18,14 +17,18 @@ has 'mech' => ( is => 'rw', lazy_build => 1 );
has 'cpan' => ( is => 'rw', isa => 'Str', default => "$ENV{HOME}/minicpan" );
has 'tar' => ( is => 'rw' );
+sub metacpan_url {
+ my $self = shift;
+ my $name = shift;
+ return "http://api.beta.metacpan.org/pod/$name?content-type=text/x-pod";
+}
+
sub convert {
my $self = shift;
my $name = shift;
- my $url
- = "http://api.beta.metacpan.org/pod/$name?content-type=text/x-pod";
- my $res = $self->mech->get( $url );
+ my $res = $self->mech->get( $self->metacpan_url( $name ) );
if ( !$res->is_success ) {
die $res->content . ' ' . $res->status_line;
@@ -35,6 +38,13 @@ sub convert {
}
+sub is_cached {
+ my $self = shift;
+ my $name = shift;
+
+ return $self->mech->is_cached( $self->metacpan_url( $name ) );
+}
+
sub parse_pod {
my $self = shift;
View
6 lib/MetaCPAN/Pod/XHTML.pm
@@ -4,15 +4,13 @@ use Moose;
extends 'Pod::Simple::XHTML';
-use Data::Dump qw( dump );
-
sub start_L {
my ( $self, $flags ) = @_;
my ( $type, $to, $section ) = @{$flags}{ 'type', 'to', 'section' };
my $file = $to;
if ( $file ) {
- $file =~ s{::}{-}g;
+ $file =~ s{::}{__}g;
$file .= '.html';
}
@@ -21,7 +19,7 @@ sub start_L {
: $type eq 'pod' ? $self->resolve_pod_page_link( $file, $section )
: $type eq 'man' ? $self->resolve_man_page_link( $to, $section )
: undef;
-
+
my $pound = '#';
my $class
= ( $type eq 'pod' && ($url !~ m{$pound}) ) ? ' class="moduleLink"' : '';
View
20 lib/Pod2HTML.pm
@@ -12,8 +12,8 @@ get '/' => sub {
get '/pod/:name' => sub {
my $pod = MetaCPAN::Pod->new;
-
- return $pod->convert( params->{name} );
+
+ return $pod->convert( params->{name} );
};
@@ -23,11 +23,23 @@ get '/podpath/**' => sub {
my $path = join( "/", @{$matches[0]} );
#return $path;
my $pod = MetaCPAN::Pod->new;
-
- return $pod->convert( $path );
+
+ return $pod->convert( $path );
};
+get '/from_cache/**' => sub {
+
+ my @matches = splat;
+ my $path = join( "/", @{$matches[0]} );
+ my $pod = MetaCPAN::Pod->new;
+
+ return $pod->convert( $path ) if $pod->is_cached( $path );
+ status 'not_found';
+
+};
+
+
true;
=pod
View
38 t/003_pod.t
@@ -1,18 +1,42 @@
-use Test::More;
use strict;
use warnings;
+use Test::More;
use MetaCPAN::Pod;
-new_ok('MetaCPAN::Pod');
+new_ok( 'MetaCPAN::Pod' );
+
+my $mcp = MetaCPAN::Pod->new;
-my $pod = MetaCPAN::Pod->new;
-
#diag( $pod->convert('Plack::Middleware::HTMLify') );
-ok( -e $pod->author_dir("OALDERS") );
+my $author = 'OALDERS';
+my $release = 'HTML-Restrict-1.0.3';
+my $path = 'lib/HTML/Restrict.pm';
+
+is( $mcp->author_dir( 'OALDERS' ),
+ "/home/wunderadmin/minicpan/authors/id/O/OA/OALDERS",
+ "author dir"
+);
+ok( -e $mcp->author_dir( $author ), "author dir exists" );
+my $pod = $mcp->local_pod( $author, $release, $path );
+ok( $pod, "got pod for $release" );
+
+my $tar = $mcp->build_tar( $author, $release );
+isa_ok( $tar, "Archive::Tar", "got tar object" );
+
+my $pod_from_tar = $mcp->pod_from_tar( $release, $path );
+ok( $pod_from_tar, "pod_from_tar" );
+
+my $url_path = join "/", $author, $release, $path;
-my $pod = $pod->local_pod( "OALDERS", "HTML-Restrict-0.06", "lib/HTML/Restrict.pm" );
-diag ( $pod );
+my $metacpan_url = $mcp->metacpan_url( $url_path );
+is( $metacpan_url,
+ 'http://api.beta.metacpan.org/pod/OALDERS/HTML-Restrict-1.0.3/lib/HTML/Restrict.pm?content-type=text/x-pod',
+ 'correct url on MetaCPAN'
+);
+my $pod_from_metacpan = $mcp->convert( $url_path );
+ok( $pod_from_metacpan, "can find pod on MetaCPAN" );
+diag( $mcp->parse_pod( $pod ) );
done_testing();

No commit comments for this range

Something went wrong with that request. Please try again.