Test::Smoke::LogMixin - "Role" that adds logging methods to "traditional" objects.
package MyPackage; use warnings; use strict; use Test::Smoke::LogMixin; sub new { my $class = shift; my %selfish = @_; $selfish{_verbose} ||= 0; return bless \%selfish, $class; } 1; package main; use MyPackage; my $o = MyPackage->new(_verbose => 2); $o->log_debug("This will end up in the log");
This package with these mixin-methods acts like a role to extend your traditional (created with bless()) object with 4 new methods. It has some extra Test::Smoke::App::Base logic to determine the log-level (by looking at $app->option('verbose')). For other object types it tries to fiend if there are methods by the name verbose or v, or maybe the keys _verbose or _v (See also Test::Smoke::ObjectBase).
bless()
$app->option('verbose')
verbose
v
_verbose
_v
The three log methods use the sprintf() way of composing strings whenever more than 1 argument is passed!
sprintf()
Return the verbosity of this app.
None.
The value of either _verbose or _v
prinf $fmt, @values to the currently selected filehandle.
prinf $fmt, @values
Positional.
The format gets an extra new line if one wasn't present.
use in void context.
prinf $fmt, @values to the currently selected filehandle if the 'verbose' option is set.
prinf $fmt, @values to the currently selected filehandle if the 'verbose' option is set to a value > 1.
Test::Smoke::Logger - Helper object for logging.
use Test::Smoke::LogMixin; my $logger = Test::Smoke::Logger->new(v => 1); $logger->log_warn("Minimal log level"); # v >= 0 $logger->log_info("Medium log level"); # v <= 1 $logger->log_debug("High log level"); # v > 1
Return a logger instance.
Named, hash:
The Test::Smoke::Logger instance.
(c) 2020, All rights reserved.
* Abe Timmerman <abeltje@cpan.org>
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See:
* <http://www.perl.com/perl/misc/Artistic.html>, * <http://www.gnu.org/copyleft/gpl.html>
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
To install Test::Smoke, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::Smoke
CPAN shell
perl -MCPAN -e shell install Test::Smoke
For more information on module installation, please visit the detailed CPAN module installation guide.