| blib/lib/Text/Md2Inao/Logger.pm | |||
|---|---|---|---|
| Criterion | Covered | Total | % |
| statement | 18 | 21 | 85.7 |
| branch | 2 | 4 | 50.0 |
| condition | 0 | 3 | 0.0 |
| subroutine | 6 | 6 | 100.0 |
| pod | 0 | 1 | 0.0 |
| total | 26 | 35 | 74.2 |
| line | stmt | bran | cond | sub | pod | time | code |
|---|---|---|---|---|---|---|---|
| 1 | package Text::Md2Inao::Logger; | ||||||
| 2 | 29 | 29 | 181 | use strict; | |||
| 29 | 61 | ||||||
| 29 | 1176 | ||||||
| 3 | 29 | 29 | 158 | use warnings; | |||
| 29 | 64 | ||||||
| 29 | 1066 | ||||||
| 4 | |||||||
| 5 | 29 | 29 | 172 | use Encode qw/encode_utf8/; | |||
| 29 | 53 | ||||||
| 29 | 3188 | ||||||
| 6 | 29 | 29 | 41780 | use Term::ANSIColor; | |||
| 29 | 469544 | ||||||
| 29 | 4264 | ||||||
| 7 | |||||||
| 8 | 29 | 29 | 358 | use parent qw/Exporter/; | |||
| 29 | 63 | ||||||
| 29 | 292 | ||||||
| 9 | our @EXPORT = qw/log/; | ||||||
| 10 | |||||||
| 11 | our $LOG; | ||||||
| 12 | our $STOP; | ||||||
| 13 | |||||||
| 14 | my %COLOR = ( | ||||||
| 15 | success => 'green', | ||||||
| 16 | warn => 'red', | ||||||
| 17 | error => 'red', | ||||||
| 18 | info => 'white', | ||||||
| 19 | ); | ||||||
| 20 | |||||||
| 21 | sub log ($$) { | ||||||
| 22 | 10 | 10 | 0 | 122 | my ($type, $msg) = @_; | ||
| 23 | 10 | 50 | 43 | if ($LOG) { | |||
| 50 | |||||||
| 24 | 0 | 0 | $LOG->($type, $msg); | ||||
| 25 | } | ||||||
| 26 | elsif (not $STOP) { | ||||||
| 27 | 0 | 0 | 0 | my $color ||= $COLOR{$type}; | |||
| 28 | 0 | 0 | print STDERR encode_utf8(Term::ANSIColor::colored sprintf("[%s] %s\n", $type, $msg), $color); | ||||
| 29 | } | ||||||
| 30 | 10 | 26 | return; | ||||
| 31 | } | ||||||
| 32 | |||||||
| 33 | 1; | ||||||
| 34 |