#!perl

use 5.010;
use strict;
use warnings;
use Log::Any '$log';

use App::PMUtils;
use Perinci::CmdLine::Any -prefer_lite=>1;

our $DATE = '2014-09-09'; # DATE
our $VERSION = '0.26'; # VERSION

our %SPEC;
$SPEC{pmcost} = {
    v => 1.1,
    summary => 'Load Perl module with Devel::EndStats',
    description => <<'_',



_
    args => {
        module => {
            schema => ['array*' => of=>'str*', min_len=>1],
            req    => 1,
            pos    => 0,
            greedy => 1,
            element_completion => $App::PMUtils::_complete_module,
        },
        hide_core => {
            schema => 'bool',
        },
        hide_noncore => {
            schema => 'bool',
        },
        show_memsize => {
            schema => 'bool',
        },
    },
};
sub pmcost {
    my %args = @_;
    my $mods = $args{module};

    my $de_import = "verbose,1";
    $de_import .= ",hide_core,1" if $args{hide_core};
    $de_import .= ",hide_noncore,1" if $args{hide_noncore};
    $de_import .= ",show_memsize,1,sort,-memsize" if $args{show_memsize};
    my @cmd = ($^X, "-MDevel::EndStats=$de_import");

    for my $mod (@$mods) {
        $mod =~ s!/!::!g;
        push @cmd, "-M$mod";
    }

    push @cmd, "-e1";

    $log->tracef("exec(%s)", \@cmd);
    exec @cmd;
    # [200]; # won't get reached
}

Perinci::CmdLine::Any->new(
    url => '/main/pmcost',
)->run;

# ABSTRACT: Load Perl module with Devel::EndStats
# PODNAME: pmcost

__END__

=pod

=encoding UTF-8

=head1 NAME

pmcost - Load Perl module with Devel::EndStats

=head1 VERSION

This document describes version 0.26 of pmcost (from Perl distribution App-PMUtils), released on 2014-09-09.

=head1 SYNOPSIS

 % pmcost Some::Module
 $ pmcost HTTP::Tiny

 # Start stats from Devel::EndStats:
 # Program runtime duration: 0.011s
 # Total number of required files loaded: 13
 # Total number of required lines loaded: 6789
 # Seq  Lines  Load Time         Module
 #  11     54     0.128ms(  1%)    SelectSaver.pm (loaded by IO::Handle)
 #  13     68     0.488ms(  4%)    IO.pm (loaded by IO::Handle)
 #   4    100     0.091ms(  0%)    bytes.pm (loaded by HTTP::Tiny)
 #  17    143     0.387ms(  3%)    IO/Socket/UNIX.pm (loaded by IO::Socket)
 #   9    170     0.306ms(  2%)    Symbol.pm (loaded by IO::Handle)
 #   5    283     0.368ms(  3%)    Errno.pm (loaded by HTTP::Tiny::Handle)
 #  14    355     0.226ms(  2%)    XSLoader.pm (loaded by IO)
 #  16    466     1.182ms( 10%)    IO/Socket/INET.pm (loaded by IO::Socket)
 #   6    569     5.831ms( 53%)    IO/Socket.pm (loaded by HTTP::Tiny::Handle)
 #   7    653     1.912ms( 17%)    IO/Handle.pm (loaded by IO::Socket)
 #   2    709     1.035ms(  9%)    Carp.pm (loaded by HTTP::Tiny)
 #  15   1114     1.328ms( 12%)    Socket.pm (loaded by IO::Socket)
 #   1   2105    10.889ms( 99%)    HTTP/Tiny.pm (loaded by main)
 # End of stats

To active bash completion:

 % complete -C pmcost pmcost ; # can be put in bash startup file e.g. .bashrc
 % pmcost Some<tab>
 % pmcost test/builder/mo<tab> ; # resolve to Test/Builder/Module, can resolve case
 % pmcost "Text::Abb<tab>      ; # use quote (' or ") if you want to use :: as separator

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/App-PMUtils>.

=head1 SOURCE

Source repository is at L<https://github.com/perlancar/perl-App-PMUtils>.

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=App-PMUtils>

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.

=head1 AUTHOR

perlancar <perlancar@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by perlancar@cpan.org.

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
