App-PMUtils
view release on metacpan or search on metacpan
script/pwd2mod view on Meta::CPAN
#!perl
use 5.010;
use strict;
use warnings;
#use App::PMUtils;
use Perinci::CmdLine::Any;
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
our $DATE = '2024-08-30'; # DATE
our $DIST = 'App-PMUtils'; # DIST
our $VERSION = '0.745'; # VERSION
our %SPEC;
$SPEC{pwd2mod} = {
v => 1.1,
summary => 'Try to guess/extract module name from current directory',
description => <<'_',
Will return `.` if module name cannot be guessed.
_
args => {
},
result_naked => 1,
};
sub pwd2mod {
my %args = @_;
my $cwd = $ENV{PWD} // do { require Cwd; Cwd::cwd() };
$cwd =~ s!.+[/\\]!!;
$cwd =~ s/^(perl|cpan|p5|pl)-//;
return '.' unless $cwd =~ /\A\w+(-\w+)*\z/;
$cwd =~ s/-/::/g;
$cwd;
}
Perinci::CmdLine::Any->new(
url => "/main/pwd2mod",
read_config => 0,
read_env => 0,
)->run;
# ABSTRACT: Try to guess/extract module name from current directory
# PODNAME: pwd2mod
__END__
=pod
=encoding UTF-8
=head1 NAME
pwd2mod - Try to guess/extract module name from current directory
=head1 VERSION
This document describes version 0.745 of pwd2mod (from Perl distribution App-PMUtils), released on 2024-08-30.
=head1 SYNOPSIS
% pwd
/home/ujang/proj/perl-Foo-Bar
% pwd2mod
Foo::Bar
% cd
% pwd
/home/ujang
% pwd2mod
.
=head1 DESCRIPTION
Will return C<.> if module name cannot be guessed.
=head1 OPTIONS
C<*> marks required options.
=head2 Output options
=over
=item B<--format>=I<s>
Choose output format, e.g. json, text.
Default value:
undef
Output can be displayed in multiple formats, and a suitable default format is
chosen depending on the application and/or whether output destination is
interactive terminal (i.e. whether output is piped). This option specifically
chooses an output format.
=item B<--json>
Set output format to json.
=item B<--naked-res>
When outputing as JSON, strip result envelope.
Default value:
0
By default, when outputing as JSON, the full enveloped result is returned, e.g.:
[200,"OK",[1,2,3],{"func.extra"=>4}]
The reason is so you can get the status (1st element), status message (2nd
element) as well as result metadata/extra result (4th element) instead of just
the result (3rd element). However, sometimes you want just the result, e.g. when
you want to pipe the result for more post-processing. In this case you can use
C<--naked-res> so you just get:
[1,2,3]
=item B<--page-result>
Filter output through a pager.
This option will pipe the output to a specified pager program. If pager program
is not specified, a suitable default e.g. C<less> is chosen.
=item B<--view-result>
View output using a viewer.
( run in 2.695 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )