Dist::Zilla::UtilRole::MaybeZilla - Soft-dependency on Dist::Zilla for Utilities.
version 0.002000
Dist::Zilla Is Great. Long Live Dist::Zilla But when you're writing a utility class, loading Dist::Zilla may be not necessary, and can make testing things harder.
Dist::Zilla
Namely, because to test anything that requires Dist::Zilla, requires that you have a valid build tree, which may be lots of unnecessary work if you only need dzil for simple things like error logging.
dzil
Or perhaps, you have other resources that you only conventionally fetch from dzil, such as the dzil build-root, for the sake of making a Git::Wrapper, but you're quite happy with passing Git::Wrapper instances directly for testing.
dzil build-root
Git::Wrapper
And I found myself doing quite a lot of the latter, and re-writing the same code everywhere to do it.
So, this role provides a zilla attribute that is ONLY required if something directly calls $self->zilla, and it fails on invocation.
zilla
$self->zilla
And provides a few utility methods, that will try to use zilla where possible, but fallback to a somewhat useful default if those are not available to you.
package MyPlugin; use Moose; with 'Dist::Zilla::UtilRole::MaybeZilla'; ... sub foo { if ( $self->has_zilla ) { $self->zilla->whatever } else { $slightlymessyoption } }
Additionally, it provides a few compatibility methods to make life easier, namely
log_debug, log, log_fatal
Which will invoke the right places in dzil if possible, but revert to a sensible default if not.
A lazy attribute, populated from plugin where possible, dieing if not.
plugin
die
A lazy attribute that dies if required and not specified.
I had intended to have logging methods on this, but they proved too messy and problematic.
More, I discovered the way Dist::Zilla handles logs is kinda problematic too, because you may have noticed,
$self->log_fatal()
May just have a predisposition from reporting the failure context being
Moose/Method/Deferred.pm
Most cases. ( ☹ )
So I'm experimentally toying with using more Log::Contextual.
Log::Contextual
See [LogContextual]
[LogContextual]
Kent Fredric <kentnl@cpan.org>
This software is copyright (c) 2017 by Kent Fredric <kentfredric@gmail.com>.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install Dist::Zilla::UtilRole::MaybeZilla, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Dist::Zilla::UtilRole::MaybeZilla
CPAN shell
perl -MCPAN -e shell install Dist::Zilla::UtilRole::MaybeZilla
For more information on module installation, please visit the detailed CPAN module installation guide.