App-Deps-Verify

 view release on metacpan or  search on metacpan

lib/App/Deps/Verify/App/VerifyDeps/Command/plupdatetask.pm  view on Meta::CPAN

package App::Deps::Verify::App::VerifyDeps::Command::plupdatetask;
$App::Deps::Verify::App::VerifyDeps::Command::plupdatetask::VERSION = '0.12.2';
use App::Deps::Verify::App::VerifyDeps -command;

use strict;
use warnings;

use Path::Tiny        qw/ path /;
use App::Deps::Verify ();

sub abstract { "update a Task::Weaver perl5 dependencies Task" }

sub description { return abstract(); }

sub opt_spec
{
    return (
        [ "input|i=s\@", "the input files" ],
        [ "mutate=s",    "the .pm file to mutate" ],
    );
}

sub validate_args
{
    my ( $self, $opt, $args ) = @_;

    # no args allowed but options!
    $self->usage_error("No args allowed") if @$args;
}

sub _mutate
{
    my ( $self, $text, $toadd ) = @_;

    my @old = ( map { s/\A=pkg\s+//r } ( $text =~ /(^=pkg [^\n]+)/gms ) );

    my %mods = ( map { $_ => 1 } @old, @$toadd );

    return join '', map { "=pkg $_\n\n" } sort keys %mods;
}

sub execute
{
    my ( $self, $opt, $args ) = @_;

    my @new = (
        grep { /\A[A-Za-z0-9_:]+\z/ }
            @{ App::Deps::Verify->new->list_perl5_modules_in_yamls(
                +{ filenames => [ @{ $opt->{input} }, ] }
            )->{perl5_modules}
            }
    );

    path( $opt->{mutate} )->edit_utf8(
        sub {
            s%^((?:=pkg\s+\S+(?:\s+\S+)?\n+)+)%
            $self->_mutate($1, \@new)
            %ems;
        }
    );

    return;
}

1;

__END__

=pod

=encoding UTF-8

=head1 VERSION

version 0.12.2

=for :stopwords cpan testmatrix url bugtracker rt cpants kwalitee diff irc mailto metadata placeholders metacpan

=head1 SUPPORT

=head2 Websites

The following websites have more information about this module, and may be of help to you. As always,



( run in 2.444 seconds using v1.01-cache-2.11-cpan-5837b0d9d2c )