[libdist-zilla-role-bootstrap-perl] 02/07: First pass built from DZP:Bootstrap::ShareDir::Dist
Axel Beckert
abe at deuxchevaux.org
Sat Aug 8 11:58:18 UTC 2015
This is an automated email from the git hooks/post-receive script.
abe pushed a commit to annotated tag 0.1.0-source
in repository libdist-zilla-role-bootstrap-perl.
commit b7e73fb3437dd131fa314df5a39c1d900bdbac44
Author: Kent Fredric <kentfredric at gmail.com>
Date: Wed Sep 4 21:18:39 2013 +1200
First pass built from DZP:Bootstrap::ShareDir::Dist
---
lib/Dist/Zilla/Role/Bootstrap.pm | 122 +++++++++++++++++++++++++++++++++++++--
1 file changed, 118 insertions(+), 4 deletions(-)
diff --git a/lib/Dist/Zilla/Role/Bootstrap.pm b/lib/Dist/Zilla/Role/Bootstrap.pm
index 173f47a..848fe0a 100644
--- a/lib/Dist/Zilla/Role/Bootstrap.pm
+++ b/lib/Dist/Zilla/Role/Bootstrap.pm
@@ -3,11 +3,125 @@ use warnings;
package Dist::Zilla::Role::Bootstrap;
-# ABSTRACT:
+# ABSTRACT: Shared logic for boostrap things.
-use Moose;
+use Moose::Role;
+use MooseX::AttributeShortcuts;
-__PACKAGE__->meta->make_immutable;
-no Moose;
+=begin MetaPOD::JSON v1.1.0
+
+{
+ "namespace":"Dist::Zilla::Role::Bootstrap",
+ "interface":"role",
+ "does":"Dist::Zilla::Role::Plugin"
+}
+
+=end MetaPOD::JSON
+
+=cut
+
+with 'Dist::Zilla::Role::Plugin';
+
+around 'dump_config' => sub {
+ my ( $orig, $self, @args ) = @_;
+ my $config = $self->$orig(@args);
+ my $localconf = {};
+ for my $var (qw( try_built fallback distname )) {
+ my $pred = 'has_' . $var;
+ if ( $self->can($pred) ) {
+ next unless $self->$pred();
+ }
+ if ( $self->can($var) ) {
+ $localconf->{$var} = $self->$var();
+ }
+ }
+ $config->{ q{} . __PACKAGE__ } = $localconf;
+ return $config;
+};
+
+has distname => ( is => ro =>, lazy => 1, builder => sub { $_[0]->zilla->name; }, );
+
+has _cwd => (
+ is => ro =>,
+ lazy => 1,
+ builder => sub {
+ require Path::Tiny;
+ require Cwd;
+ return Path::Tiny::path( Cwd::cwd() );
+ },
+);
+
+=attr C<try_built>
+
+=cut
+
+has try_built => (
+ is => ro =>,
+ lazy => 1,
+ builder => sub { return },
+);
+
+=attr C<fallback>
+
+=cut
+
+has fallback => (
+ is => ro =>,
+ lazy => 1,
+ builder => sub { return 1 },
+);
+
+=p_attr C<_bootstrap_root>
+
+=cut
+
+has _bootstrap_root => (
+ is => ro =>,
+ lazy => 1,
+ builder => sub {
+ my ($self) = @_;
+ if ( not $self->try_built ) {
+ return $self->_cwd;
+ }
+ my $distname = $self->distname;
+ my (@candidates) = grep { $_->basename =~ /\A\Q$distname\E-/msx } grep { $_->is_dir } $self->_cwd->children;
+
+ if ( scalar @candidates == 1 ) {
+ return $candidates[0];
+ }
+ $self->log_debug( [ 'candidate: %s', $_->basename ] ) for @candidates;
+
+ if ( not $self->fallback ) {
+ $self->log( [ 'candidates for bootstrap (%s) != 1, and fallback disabled. not bootstrapping', 0 + @candidates ] );
+ return;
+ }
+
+ $self->log( [ 'candidates for bootstrap (%s) != 1, fallback to boostrapping <distname>/', 0 + @candidates ] );
+ return $self->_cwd;
+ },
+);
+
+sub _add_inc {
+ my ( $self, $import ) = @_;
+ if ( not ref $import ) {
+ require lib;
+ return lib->import($import);
+ }
+ die "At this time, _add_inc(arg) only supports scalar values of arg";
+}
+
+requires 'bootstrap';
+
+around plugin_from_config => sub {
+ my ( $orig, $plugin_class, $name, $payload, $section ) = @_;
+
+ my $instance = $plugin_class->$orig( $name, $payload, $section );
+
+ $instance->bootstrap;
+
+ return $instance;
+};
+
+no Moose::Role;
1;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libdist-zilla-role-bootstrap-perl.git
More information about the Pkg-perl-cvs-commits
mailing list