Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kentnl/dist-zilla-util-currentcmd
Attempt to determine the current command Dist::Zilla is running under
https://github.com/kentnl/dist-zilla-util-currentcmd
dist-zilla perl
Last synced: 4 days ago
JSON representation
Attempt to determine the current command Dist::Zilla is running under
- Host: GitHub
- URL: https://github.com/kentnl/dist-zilla-util-currentcmd
- Owner: kentnl
- License: other
- Created: 2014-05-25T18:12:48.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-03-03T11:39:17.000Z (over 7 years ago)
- Last Synced: 2023-08-20T22:28:50.163Z (about 1 year ago)
- Topics: dist-zilla, perl
- Language: Perl
- Size: 119 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.mkdn
- Changelog: Changes
- License: LICENSE
Awesome Lists containing this project
README
# NAME
Dist::Zilla::Util::CurrentCmd - Attempt to determine the current command Dist::Zilla is running under.
# VERSION
version 0.002004
# SYNOPSIS
use Dist::Zilla::Util::CurrentCmd qw(current_cmd);
...
if ( is_install() ) {
die "This plugin hates installing things for some reason!"
}
if ( is_build() ) {
print "I Love you man\n";
}
if ( current_cmd() eq 'run' ) {
die "RUN THE OTHER WAY"
}# DESCRIPTION
This module exists in case you are absolutely certain you want to have different behaviors for either a plugin, or a bundle, to
trigger on ( or off ) a specific phase.Usually, this is a bad idea, and the need to do this suggests a poor choice of work-flow to begin with.
That said, this utility is _probably_ more useful in a bundle than in a plugin, in that it will be slightly more optimal than
say, having an `ENV` flag to control this difference.# FUNCTIONS
## `current_cmd`
Returns the name of the of the **first** `command` entry in the `caller` stack that matches
/\ADist::Zilla::App::Command::(.*)::([^:\s]+)\z/msx
For instance:
Dist::Zilla::App::Command::build::execute ->
build## `is_build`
Convenience shorthand for `current_cmd() eq 'build'`
## `is_install`
Convenience shorthand for `current_cmd() eq 'install'`
## `as_cmd`
Internals wrapper to lie to code operating in the callback that the `current_cmd` is.
as_cmd('install' => sub {
is_install(); # true
});
# CAVEATS
User beware, this code is both hackish and new, and relies on using `caller` to determine which
`Dist::Zilla::App::Command::` we are running under.There may be conditions that there are no `Command`s in the `caller` stack which meet this definition, or the _first_ such
thing may be a misleading representation of what is actually running.And there's a degree of uncertainty of reliability, because I haven't yet devised reliable ways of testing it that don't
involve invoking `dzil` ( which is problematic on testers where `Dist::Zilla` is in `@INC` but `dzil` is not in
`ENV{PATH}` )To that extent, I don't even know for sure if this module works yet, or if it works in a bundle, or if it works in all
commands, or if it works under `Dist::Zilla::App::Tester` as expected.# AUTHOR
Kent Fredric
# COPYRIGHT AND LICENSE
This software is copyright (c) 2017 by Kent Fredric .
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.