Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Migrate all files into Module::CPANfile for easy inclusion

  • Loading branch information...
commit 1e44b59e355ae7d6430245f0313757cf7a0e4a49 1 parent 57ba077
@miyagawa authored
View
116 lib/Module/CPANfile.pm
@@ -2,7 +2,6 @@ package Module::CPANfile;
use strict;
use warnings;
use Cwd;
-use Module::CPANfile::Environment;
our $VERSION = '0.9004';
@@ -37,6 +36,121 @@ sub prereq_specs {
$self->{result}{spec};
}
+package Module::CPANfile::Environment;
+use strict;
+
+my @bindings = qw(
+ on requires recommends suggests conflicts
+ osname perl
+ configure_requires build_requires test_requires author_requires
+);
+
+my $file_id = 1;
+
+sub import {
+ my($class, $result_ref) = @_;
+ my $pkg = caller;
+
+ $$result_ref = Module::CPANfile::Result->new;
+ for my $binding (@bindings) {
+ no strict 'refs';
+ *{"$pkg\::$binding"} = sub { $$result_ref->$binding(@_) };
+ }
+}
+
+sub parse {
+ my $file = shift;
+
+ my $code = do {
+ open my $fh, "<", $file or die "$file: $!";
+ join '', <$fh>;
+ };
+
+ my($res, $err);
+
+ {
+ local $@;
+ $res = eval sprintf <<EVAL, $file_id++;
+package Module::CPANfile::Sandbox%d;
+no warnings;
+my \$_result;
+BEGIN { import Module::CPANfile::Environment \\\$_result };
+
+$code;
+
+\$_result;
+EVAL
+ $err = $@;
+ }
+
+ if ($err) { die "Parsing $file failed: $err" };
+
+ return $res;
+}
+
+package Module::CPANfile::Result;
+use strict;
+
+sub new {
+ bless {
+ phase => 'runtime', # default phase
+ spec => {},
+ }, shift;
+}
+
+sub on {
+ my($self, $phase, $code) = @_;
+ local $self->{phase} = $phase;
+ $code->()
+}
+
+sub osname { die "TODO" }
+sub perl { die "TODO" }
+
+sub requires {
+ my($self, $module, $requirement) = @_;
+ $self->{spec}{$self->{phase}}{requires}{$module} = $requirement || 0;
+}
+
+sub recommends {
+ my($self, $module, $requirement) = @_;
+ $self->{spec}->{$self->{phase}}{recommends}{$module} = $requirement || 0;
+}
+
+sub suggests {
+ my($self, $module, $requirement) = @_;
+ $self->{spec}->{$self->{phase}}{suggests}{$module} = $requirement || 0;
+}
+
+sub conflicts {
+ my($self, $module, $requirement) = @_;
+ $self->{spec}->{$self->{phase}}{conflicts}{$module} = $requirement || 0;
+}
+
+# Module::Install compatible shortcuts
+
+sub configure_requires {
+ my($self, @args) = @_;
+ $self->on(configure => sub { $self->requires(@args) });
+}
+
+sub build_requires {
+ my($self, @args) = @_;
+ $self->on(build => sub { $self->requires(@args) });
+}
+
+sub test_requires {
+ my($self, @args) = @_;
+ $self->on(test => sub { $self->requires(@args) });
+}
+
+sub author_requires {
+ my($self, @args) = @_;
+ $self->on(develop => sub { $self->requires(@args) });
+}
+
+package Module::CPANfile;
+
1;
__END__
View
54 lib/Module/CPANfile/Environment.pm
@@ -1,54 +0,0 @@
-package Module::CPANfile::Environment;
-use strict;
-use Module::CPANfile::Result;
-
-my @bindings = qw(
- on requires recommends suggests conflicts
- osname perl
- configure_requires build_requires test_requires author_requires
-);
-
-my $file_id = 1;
-
-sub import {
- my($class, $result_ref) = @_;
- my $pkg = caller;
-
- $$result_ref = Module::CPANfile::Result->new;
- for my $binding (@bindings) {
- no strict 'refs';
- *{"$pkg\::$binding"} = sub { $$result_ref->$binding(@_) };
- }
-}
-
-sub parse {
- my $file = shift;
-
- my $code = do {
- open my $fh, "<", $file or die "$file: $!";
- join '', <$fh>;
- };
-
- my($res, $err);
-
- {
- local $@;
- $res = eval sprintf <<EVAL, $file_id++;
-package Module::CPANfile::Sandbox%d;
-my \$_result;
-no warnings;
-use Module::CPANfile::Environment \\\$_result;
-
-$code;
-
-\$_result;
-EVAL
- $err = $@;
- }
-
- if ($err) { die "Parsing $file failed: $err" };
-
- return $res;
-}
-
-1;
View
62 lib/Module/CPANfile/Result.pm
@@ -1,62 +0,0 @@
-package Module::CPANfile::Result;
-use strict;
-
-sub new {
- bless {
- phase => 'runtime', # default phase
- spec => {},
- }, shift;
-}
-
-sub on {
- my($self, $phase, $code) = @_;
- local $self->{phase} = $phase;
- $code->()
-}
-
-sub osname { die "TODO" }
-sub perl { die "TODO" }
-
-sub requires {
- my($self, $module, $requirement) = @_;
- $self->{spec}{$self->{phase}}{requires}{$module} = $requirement || 0;
-}
-
-sub recommends {
- my($self, $module, $requirement) = @_;
- $self->{spec}->{$self->{phase}}{recommends}{$module} = $requirement || 0;
-}
-
-sub suggests {
- my($self, $module, $requirement) = @_;
- $self->{spec}->{$self->{phase}}{suggests}{$module} = $requirement || 0;
-}
-
-sub conflicts {
- my($self, $module, $requirement) = @_;
- $self->{spec}->{$self->{phase}}{conflicts}{$module} = $requirement || 0;
-}
-
-# Module::Install compatible shortcuts
-
-sub configure_requires {
- my($self, @args) = @_;
- $self->on(configure => sub { $self->requires(@args) });
-}
-
-sub build_requires {
- my($self, @args) = @_;
- $self->on(build => sub { $self->requires(@args) });
-}
-
-sub test_requires {
- my($self, @args) = @_;
- $self->on(test => sub { $self->requires(@args) });
-}
-
-sub author_requires {
- my($self, @args) = @_;
- $self->on(develop => sub { $self->requires(@args) });
-}
-
-1;
Please sign in to comment.
Something went wrong with that request. Please try again.