Permalink
Browse files

update to document classes and tests

  • Loading branch information...
monken committed Feb 13, 2011
1 parent aacf961 commit db49446e51df371f55246a260ef054325c069dad
Showing with 102 additions and 32 deletions.
  1. +0 −1 lib/ElasticSearch/Document.pm
  2. +32 −23 lib/MetaCPAN/Document/File.pm
  3. +67 −5 t/document/file.t
  4. +3 −3 t/document/module.t
@@ -28,7 +28,6 @@ use MooseX::Attribute::Deflator;
deflate 'Bool', via { \$_ };
deflate 'File::stat', via { return { List::MoreUtils::mesh(@stat, @$_) } };
deflate 'ScalarRef', via { $$_ };
-deflate 'ArrayRef', via { encode_json($_) };
deflate 'DateTime', via { $_->iso8601 };
no MooseX::Attribute::Deflator;
@@ -12,29 +12,26 @@ use Pod::Text;
use Plack::MIME;
use List::MoreUtils qw(uniq);
-Plack::MIME->add_type( ".t" => "text/x-script.perl" );
-Plack::MIME->add_type( ".xs" => "text/x-c" );
+Plack::MIME->add_type( ".t" => "text/x-script.perl" );
+Plack::MIME->add_type( ".pod" => "text/x-script.perl" );
+Plack::MIME->add_type( ".xs" => "text/x-c" );
has id => ( id => [qw(author release path)] );
-has path => ( index => 'not_analyzed' );
-has author => ( index => 'not_analyzed' );
-has name => ( required => 1, index => 'not_analyzed' );
+has [qw(path author name release distribution)] => ();
has binary => ( isa => 'Bool', default => 0 );
-has url => ( lazy_build => 1, index => 'no' );
-has stat => ( isa => 'File::stat', handles => [qw(size)], type => 'object' );
-has release => ( required => 1, index => 'not_analyzed' );
-has sloc => ( isa => 'Int', lazy_build => 1 );
-has pod_lines => ( isa => 'ArrayRef', lazy_build => 1, index => 'no' );
-has pod_txt => ( isa => 'ScalarRef', lazy_build => 1 );
-has pod_html => ( isa => 'ScalarRef', lazy_build => 1, index => 'no' );
-has toc => ( isa => 'ArrayRef', lazy_build => 1, index => 'no' );
-has mime => ( lazy_build => 1 );
-
-has pod => ( isa => 'ScalarRef', lazy_build => 1, property => 0 );
-has content => ( isa => 'ScalarRef', property => 0, required => 0 );
-has ppi => ( isa => 'PPI::Document', lazy_build => 1, property => 0 );
-has abstract => ( isa => 'Str', lazy_build => 1, property => 0 );
+has url => ( lazy_build => 1, index => 'no' );
+has stat => ( isa => 'File::stat', handles => [qw(size)], type => 'object' );
+has sloc => ( isa => 'Int', lazy_build => 1 );
+has pod_lines => ( isa => 'ArrayRef', type => 'integer', lazy_build => 1, index => 'no' );
+has pod_txt => ( isa => 'ScalarRef', lazy_build => 1 );
+has pod_html => ( isa => 'ScalarRef', lazy_build => 1, index => 'no' );
+has toc => ( isa => 'ArrayRef', type => 'object', lazy_build => 1, index => 'no' );
+has [qw(mime module abstract)] => ( lazy_build => 1 );
+
+has pod => ( isa => 'ScalarRef', lazy_build => 1, property => 0 );
+has content => ( isa => 'ScalarRef', property => 0, required => 0 );
+has ppi => ( isa => 'PPI::Document', lazy_build => 1, property => 0 );
has pom => ( lazy_build => 1, property => 0, required => 0 );
sub is_perl_file {
@@ -50,22 +47,34 @@ sub _build_pom {
Pod::POM->new( warn => 0 )->parse_text( ${ $self->content } );
}
-sub _build_abstract {
+sub _build_module {
my $self = shift;
return '' unless ( $self->is_perl_file );
my $pom = $self->pom;
foreach my $s ( @{ $pom->head1 } ) {
if ( $s->title eq 'NAME' ) {
my $content = $s->content;
- $content =~ s{\A.*\-\s}{};
- $content =~ s{\s*\z}{};
+ $content =~ s/^(.*?)\s*(-.*)?$/$1/s;
+ return $content || '';
+ }
+ }
+ return '';
+}
+
+sub _build_abstract {
+ my $self = shift;
+ return '' unless ( $self->is_perl_file );
+ my $pom = $self->pom;
+ foreach my $s ( @{ $pom->head1 } ) {
+ if ( $s->title eq 'NAME' ) {
+ return '' unless ( $s->content =~ /^.*?\s*-\s*(.*)$/s );
+ my $content = $1;
# MOBY::Config has more than one POD section in the abstract after
# parsing Should have a closer look and file bug with Pod::POM
# It also contains newlines in the actual source
$content =~ s{=head.*}{}xms;
$content =~ s{\n}{}gxms;
-
return $content || '';
}
}
View
@@ -5,18 +5,80 @@ use warnings;
use MetaCPAN::Document::File;
use File::stat;
-my $content = <<'END';
+{
+ my $content = <<'END';
=head1 NAME
MyModule - mymodule1 abstract
END
+ my $file =
+ MetaCPAN::Document::File->new( author => 'Foo',
+ path => 'bar',
+ release => 'release',
+ distribution => 'foo',
+ name => 'module.pm',
+ stat => File::stat->new,
+ content => \$content );
-my $file = MetaCPAN::Document::File->new( author => 'Foo', path => 'bar', release => 'release', name => 'module.pm', stat => File::stat->new, content => \$content );
+ is( $file->abstract, 'mymodule1 abstract' );
+ is( $file->module, 'MyModule' );
+ is_deeply( $file->toc, [ { text => 'NAME', leaf => \1 } ] );
+}
+{
+ my $content = <<'END';
+=head1 NAME
+
+MyModule
+
+END
+
+ my $file =
+ MetaCPAN::Document::File->new( author => 'Foo',
+ path => 'bar',
+ release => 'release',
+ distribution => 'foo',
+ name => 'module.pm',
+ stat => File::stat->new,
+ content => \$content );
+
+ is( $file->abstract, '' );
+ is( $file->module, 'MyModule' );
+ is_deeply( $file->toc, [ { text => 'NAME', leaf => \1 } ] );
+}
+{
+ my $content = <<'END';
+#$Id: Config.pm,v 1.5 2008/09/02 13:14:18 kawas Exp $
+
+=head1 NAME
+
+MOBY::Config.pm - An object containing information about how to get access to teh Moby databases, resources, etc. from the
+mobycentral.config file
+
+=cut
+
+
+=head2 USAGE
+END
-is($file->abstract, 'mymodule1 abstract');
-is_deeply($file->toc, [{ text => 'NAME', leaf => \1 }]);
+ my $file =
+ MetaCPAN::Document::File->new( author => 'Foo',
+ path => 'bar',
+ release => 'release',
+ distribution => 'foo',
+ name => 'module.pm',
+ stat => File::stat->new,
+ content => \$content );
+ is( $file->abstract,
+'An object containing information about how to get access to teh Moby databases, resources, etc. from the mobycentral.config file'
+ );
+ is( $file->module, 'MOBY::Config.pm' );
+ is_deeply( $file->toc,
+ [
+ { text => 'NAME',
+ children => [ { text => 'USAGE', leaf => \1 } ] } ] );
+}
-done_testing;
+done_testing;
View
@@ -6,6 +6,7 @@ use MetaCPAN::Document::Module;
use File::stat;
use Digest::SHA1;
use DateTime;
+use MetaCPAN::Util;
my $module =
MetaCPAN::Document::Module->new( file => '',
@@ -17,8 +18,7 @@ my $module =
date => DateTime->now,
abstract => '' );
-my $digest = Digest::SHA1::sha1_base64("PERLER\0CPAN-API-0.1\0Api.pm");
-$digest =~ tr/[+\/]/-_/;
-is( $module->id, $digest );
+my $id = MetaCPAN::Util::digest(qw(PERLER CPAN-API-0.1 Api.pm));
+is( $module->id, $id );
done_testing;

0 comments on commit db49446

Please sign in to comment.