Permalink
Browse files

Adds more tests to Pod creation

  • Loading branch information...
1 parent 80d81d5 commit f81e6d360cd65b346e60340968b1b3253cc22d36 @oalders committed Apr 24, 2012
Showing with 44 additions and 19 deletions.
  1. +7 −4 lib/MetaCPAN/Pod.pm
  2. +2 −4 lib/MetaCPAN/Pod/XHTML.pm
  3. +4 −4 lib/Pod2HTML.pm
  4. +31 −7 t/003_pod.t
View
@@ -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;
@@ -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
@@ -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,8 +23,8 @@ get '/podpath/**' => sub {
my $path = join( "/", @{$matches[0]} );
#return $path;
my $pod = MetaCPAN::Pod->new;
-
- return $pod->convert( $path );
+
+ return $pod->convert( $path );
};
View
@@ -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();

0 comments on commit f81e6d3

Please sign in to comment.