App-Sqitch
view release on metacpan or search on metacpan
lib/App/Sqitch/ItemFormatter.pm view on Meta::CPAN
package App::Sqitch::ItemFormatter;
use 5.010;
use strict;
use warnings;
use utf8;
use Locale::TextDomain qw(App-Sqitch);
use App::Sqitch::X qw(hurl);
use List::Util qw(max);
use Moo;
use Types::Standard qw(Str Int);
use Type::Utils qw(enum class_type);
use String::Formatter;
use namespace::autoclean;
use Try::Tiny;
use Term::ANSIColor 2.02 qw(colorvalid);
my $encolor = \&Term::ANSIColor::color;
use constant CAN_OUTPUT_COLOR => $^O eq 'MSWin32'
? try { require Win32::Console::ANSI }
: -t *STDOUT;
BEGIN {
$ENV{ANSI_COLORS_DISABLED} = 1 unless CAN_OUTPUT_COLOR;
}
our $VERSION = 'v1.6.1'; # VERSION
has abbrev => (
is => 'ro',
isa => Int,
default => 0,
);
has date_format => (
is => 'ro',
isa => Str,
default => 'iso',
);
has color => (
is => 'ro',
isa => enum([ qw(always never auto) ]),
default => 'auto',
);
has formatter => (
is => 'ro',
lazy => 1,
isa => class_type('String::Formatter'),
default => sub {
my $self = shift;
String::Formatter->new({
input_processor => 'require_single_input',
string_replacer => 'method_replace',
codes => {
e => sub { $_[0]->{event} },
L => sub {
my $e = $_[0]->{event};
return $e eq 'deploy' ? __ 'Deploy'
: $e eq 'revert' ? __ 'Revert'
: $e eq 'fail' ? __ 'Fail'
: hurl "Unknown event type $e"; # should not happen
},
l => sub {
my $e = $_[0]->{event};
return $e eq 'deploy' ? __ 'deploy'
: $e eq 'revert' ? __ 'revert'
: $e eq 'fail' ? __ 'fail'
: hurl "Unknown event type $e"; # should not happen
},
_ => sub {
my $x = $_[1];
hurl format => __ 'No label passed to the _ format'
unless defined $x;
( run in 1.391 second using v1.01-cache-2.11-cpan-75ffa21a3d4 )