App-GitFind

 view release on metacpan or  search on metacpan

lib/App/GitFind/Base.pm  view on Meta::CPAN

    my @retval;
    for(split "\n", $_[0]//'') {
        chomp;
        s{#.*$}{};                      # Remove comments
        s{(?:^\s+)|(?:\s+$)}{}g;        # Remove leading/trailing ws
        push @retval, grep { length } split /\s+/;
    }
    return @retval;
} #_qwc()

=head2 getparameters

An alias of the C<parameters()> function from L<Getargs::Mixed>, but with
C<-undef_ok> set.

=cut

sub getparameters {
    state $GM = (require Getargs::Mixed, Getargs::Mixed->new(-undef_ok => true));

    unshift @_, $GM;
    goto &Getargs::Mixed::parameters;
} #getparameters()

=head2 ddc

L<Data::Dumper::Compact/ddc>, but lazily loads C<Data::Dumper::Compact>.

=cut

sub ddc {
    state $dumpcb = (require Data::Dumper::Compact, Data::Dumper::Compact->new->dump_cb);
    goto &$dumpcb;
}

=head2 croak

As L<Carp/croak>, but lazily loads C<Carp>.

=cut

sub croak {
    require Carp;
    goto &Carp::croak;
}

=head2 vlog

Log information to STDERR if L</$VERBOSE> is set.  Usage:

    vlog { <list of things to log> }
        [optional min verbosity level (default 1)]
        [, log-routine args];

The items in the list are joined by C<' '> on output, and a C<'\n'> is added.
Each line is prefixed with C<'# '> for the benefit of test runs.
To break the list across multiple lines, specify C<\n> at the beginning of
a list item.

The list is in C<{}> so that it won't be evaluated if logging is turned off.
It is a full block, so you can run arbitrary code to decide what to log.
If the block returns an empty list, vlog will not produce any output.
However, if the block returns at least one element, vlog will produce at
least a C<'# '>.

The message will be output only if L</$VERBOSE> is at least the given minimum
verbosity level (1 by default).

If C<< $VERBOSE >= 4 >>, the filename and line from which vlog was called
will also be printed.

If more arguments are provided than two, the extras are the arguments
to the subroutine.  This permits you to pass arguments from the caller's
C<@_> that would otherwise be shadowed inside the logging routine.  E.g.:

    sub foo {
        vlog { $_[0] } 1, $_[1];    # log foo's $_[1]
    }

=cut

sub vlog (&;@) {
    return if $QUIET;
    my ($crRoutine, $level) = splice @_, 0, 2;
    return unless $VERBOSE >= ($level // 1);

    my @log = $crRoutine->(@_);
    return unless @log;

    chomp $log[$#log] if $log[$#log];
    # TODO add an option to number the lines of the output
    my $msg = join(' ', @log);
    $msg =~ s/^/# /gm;

    if($VERBOSE >= 4) {
        my ($package, $filename, $line) = caller;
        $msg .= " (at $filename:$line)";
    }

    say STDERR $msg;
} #vlog()

=head2 vwarn

As L</vlog>, but warns regardless of L</$VERBOSE>.  Does respect L</$QUIET>.

=cut

sub vwarn (&) {
    return if $QUIET;

    my @log = &{$_[0]}();
    return unless @log;

    vlog { "Warning:", @log } $VERBOSE;
} #vwarn()

=head2 import

See L</SYNOPSIS>



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