Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Changed the API to prefer load()

  • Loading branch information...
commit 527c25800a9938332d36de9d366f60c82c956a05 1 parent 6c0324e
@miyagawa authored
Showing with 13 additions and 4 deletions.
  1. +8 −2 lib/CPANfile.pm
  2. +5 −2 t/parse.t
View
10 lib/CPANfile.pm
@@ -6,7 +6,13 @@ use CPANfile::Environment ();
sub new {
my($class, $file) = @_;
- my $self = bless { file => $file || "cpanfile" }, $class;
+ bless {}, $class;
+}
+
+sub load {
+ my($proto, $file) = @_;
+ my $self = ref $proto ? $proto : $proto->new;
+ $self->{file} = $file || "cpanfile";
$self->parse;
$self;
}
@@ -41,7 +47,7 @@ CPANfile - Parse cpanfile
use CPANfile;
- my $file = CPANfile->new("cpanfile");
+ my $file = CPANfile->load("cpanfile");
my $meta = $file->prereqs; # CPAN::Meta::Prereqs object
=head1 DESCRIPTION
View
7 t/parse.t
@@ -5,11 +5,14 @@ use Cwd;
use File::Basename qw(dirname);
use t::Utils;
+eval { require CPAN::Meta::Prereqs; 1 }
+ or plan skip_all => "CPAN::Meta::Prereqs not found";
+
chdir "t/samples";
{
eval {
- my $file = CPANfile->new;
+ my $file = CPANfile->load;
};
like $@, qr/No such file/;
}
@@ -35,7 +38,7 @@ test_requires 'Test::Warn', 0.1;
author_requires 'Module::Install', 0.99;
FILE
- my $file = CPANfile->new;
+ my $file = CPANfile->load;
my $prereq = $file->prereq;
is_deeply $prereq->as_string_hash, {
Please sign in to comment.
Something went wrong with that request. Please try again.