App-pmodinfo

 view release on metacpan or  search on metacpan

lib/App/pmodinfo.pm  view on Meta::CPAN

    my ( $self, $module ) = @_;
    $module =~ s/::/-/g;
    return "http://search.cpan.org/dist/$module";
}

sub update_modules {
    my ( $self, @modules ) = @_;
    my $cpan_util;
    $cpan_util = which('cpanm') or which('cpan') or exit -1;
    system( $cpan_util, @modules );
    exit 0;
}

sub ns_argv {
    my $self = shift;
    my @nargv;
    my @installed = $self->installed_modules;

    foreach my $arg ( @{ $self->{argv} } ) {
        if ($arg =~ /::$/) {
            my $mod = $arg;
            $mod =~ s/::$//;
            push( @nargv, $mod);
        } else {
            push( @nargv, $arg );
        }
    }

    foreach my $mod (@installed) {
        foreach my $arg ( @{ $self->{argv} } ) {
            next unless $arg =~ /::$/;
            next unless $mod =~ /^$arg/;
            push( @nargv, $mod );
        }
    }

    $self->{argv} = \@nargv;
}

sub check_installed_modules_for_update {
    my $self = shift;
    my @need_update;

    $self->ns_argv;

    foreach my $module ( scalar( @{ $self->{argv} } ) ? @{ $self->{argv} } : $self->installed_modules ) {
        my ( $install, $meta ) = $self->check_module( $module, 0 );
        next unless $install and defined($meta);

        my $local_version = $meta->version;
        my $cpan_version  = $self->get_last_version_from_cpan($module);
        next unless $cpan_version and $local_version;
        next if $cpan_version eq $local_version;

        print "$module local version: $local_version, last version in cpan: $cpan_version\n";

        push( @need_update, $module );
    }

    if ( scalar(@need_update) ) {
        my $ans = lc $self->prompt( "Do you need to update this modules now ? (y/n)", "n" );
        $self->update_modules(@need_update) if $ans eq 'y';
    }
    else {
        print "already up to date.";
    }

    exit 0;
}

sub prompt {
    my ( $self, $mess, $def ) = @_;

    my $isa_tty = -t STDIN && ( -t STDOUT || !( -f STDOUT || -c STDOUT ) );
    my $dispdef = defined $def ? "[$def] " : " ";
    $def = defined $def ? $def : "";

    if ( ( !$isa_tty && eof STDIN ) ) {
        return $def;
    }

    local $| = 1;
    local $\;
    my $ans;
    eval {
        local $SIG{ALRM} = sub {
            undef $ans;
            die "alarm\n";
        };
        print STDOUT "$mess $dispdef";
        $ans = <STDIN>;
        alarm 0;
    };
    if ( defined $ans ) {
        chomp $ans;
    }
    else {    # user hit ctrl-D or alarm timeout
        print STDOUT "\n";
    }

    return ( !defined $ans || $ans eq '' ) ? $def : $ans;
}

sub show_installed_modules {
    my $self = shift;

    $self->ns_argv;

    foreach my $module ( scalar( @{ $self->{argv} } ) ? @{ $self->{argv} } : $self->installed_modules ) {
        my ( $install, $meta, $deprecated ) = $self->check_module( $module, 0 );
        next unless $install and $meta->version;
        print "$module version is " . $meta->version;
        print "(deprecated)" if defined($deprecated);
        print ".\n";
    }
    exit 0;
}

sub installed_modules {
    my $self    = shift;
    my $inst    = ExtUtils::Installed->new();
    my @modules = $inst->modules();
    return @modules;
}

sub show_modules {
    my ( $self, $module ) = @_;
    my ( $install, $meta, $deprecated ) = $self->check_module( $module, 0 );

    print "$module not found.\n" and return unless $install and $meta->version;

lib/App/pmodinfo.pm  view on Meta::CPAN

        require Module::CoreList;
        Module::CoreList::is_deprecated( $meta->{module} );
    };

    return unless $deprecated;
    return $self->loaded_from_perl_lib($meta);
}

sub loaded_from_perl_lib {
    my ( $self, $meta ) = @_;

    require Config;
    for my $dir (qw(archlibexp privlibexp)) {
        my $confdir = $Config{$dir};
        if ( $confdir eq substr( $meta->filename, 0, length($confdir) ) ) {
            return 1;
        }
    }

    return;
}

1;


=pod

=head1 NAME

App::pmodinfo - Perl module info command line.

=head1 VERSION

version 0.10

=head1 DESCRIPTION

pmodinfo extracts information from the perl modules given the command
line, usign L<Module::Metadata>, L<Module::CoreList>, L<Module::Build>,
L<Parse::CPAN::Meta> and L<ExtUtils::Installed>.

I don't want to use more "perl -MModule\ 999".

See L<pmodinfo> for more information.

=head1 DEVELOPMENT

App::modinfo is a open source project for everyone to participate. The code
repository is located on github. Feel free to send a bug report or a pull
request.

L<http://www.github.com/maluco/App-pmodinfo>

=head1 SEE ALSO

L<Module::Metadata>, L<Module::CoreList>, L<Module::Build>,
L<Parse::CPAN::Meta>, L<ExtUtils::Installed>.

=head1 ACKNOWLEDGE

L<cpanminus>, for the check_module, prompt function and inspiration. :-)

=head1 AUTHOR

Thiago Rondon <thiago@nsms.com.br>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2011 by Thiago Rondon.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut


__END__

# ABSTRACT: Perl module info command line.




( run in 0.461 second using v1.01-cache-2.11-cpan-0b5f733616e )