App-GitGot
view release on metacpan or search on metacpan
lib/App/GitGot/Command/lib.pm view on Meta::CPAN
package App::GitGot::Command::lib;
our $AUTHORITY = 'cpan:GENEHACK';
$App::GitGot::Command::lib::VERSION = '1.339';
# ABSTRACT: Generate a lib listing off a .gotlib file
use 5.014;
use List::Util qw/ uniq /;
use Path::Tiny;
use Types::Standard -types;
use App::GitGot -command;
use Moo;
extends 'App::GitGot::Command';
use namespace::autoclean;
sub options {
my( $class , $app ) = @_;
return (
[ 'gotlib=s' => 'gotlib file' => { default => '.gotlib' } ] ,
[ 'libvar=s' => 'library environment variable' => { default => 'PERL5LIB' } ] ,
[ 'separator=s' => 'library path separator' => { default => ':' } ] ,
);
}
sub _execute {
my( $self, $opt, $args ) = @_;
my @libs = map { $self->_expand_lib($_) } $self->_raw_libs( $args );
no warnings; # $ENV{$self->opt->libvar} can be undefined
say join $self->opt->separator, uniq @libs, split ':', $ENV{$self->opt->libvar};
}
sub _expand_lib {
my( $self, $lib ) = @_;
return path($lib)->absolute if $lib =~ m#^(?:\.|/)#;
if ( $lib =~ s/^\@(\w+)// ) {
# it's a tag
return map { $_->path . $lib } $self->search_repos->tags($1)->all;
}
# it's a repo name
$lib =~ s#^([^/]+)## or return;
return map { $_->path . $lib } $self->search_repos->name($1)->all;
}
sub _raw_libs {
my( $self, $args ) = @_;
my $file = path( $self->opt->gotlib );
return @$args,
# remove comments and clean whitespaces
grep { $_ }
map { s/^\s+|#.*|\s+$//gr }
( -f $file ) ? $file->lines({ chomp => 1 }) : ();
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
App::GitGot::Command::lib - Generate a lib listing off a .gotlib file
=head1 VERSION
version 1.339
=head1 SYNOPSIS
$ echo '@dancer/lib' > .gotlib
$ export PERL5LIB=`got lib yet_another_repo_name/lib`
# PERL5LIB will now hold the path to the 'lib'
# subdirectory of 'yet_another_repo_name', followed
# by the 'lib' directories of all repos tagged with 'dancer',
# followed by the original paths of PERL5LIB
=head1 DESCRIPTION
Got's C<lib> subcommand is a Got-aware answer to L<ylib> and L<Devel::Local>,
( run in 2.895 seconds using v1.01-cache-2.11-cpan-f03e8824b8d )