use
open
qw( :std :utf8 )
;
if
(
grep
/\P{ASCII}/ =>
@ARGV
) {
@ARGV
=
map
{ decode(
'UTF-8'
,
$_
) }
@ARGV
;
}
use
Carp
qw( carp croak confess cluck )
;
local
$SIG
{ __DIE__ } =
sub
{
confess
"Uncaught exception: @_"
unless
$^S;
};
local
$SIG
{ __WARN__ } =
sub
{
if
( $^S ) { cluck
"Trapped warning: @_"
}
else
{ confess
"Deadly warning: @_"
}
};
sub
new {
my
$class
=
shift
;
my
$self
=
$class
->SUPER::new(
@_
);
bless
$self
,
$class
;
$self
->objectify(
'items'
);
$self
->{
'items'
} = [
grep
{
defined
$_
} @{
$self
->{
'items'
} } ];
return
$self
;
}
sub
as_text {
my
$self
=
shift
;
return
sprintf
(
'( %s )'
,
join
(
', '
,
map
{
$_
->as_text } @{
$self
->{
'items'
} } )
);
}
sub
pretty_print {
my
$self
=
shift
;
my
$values_as_string
=
$self
->as_text;
my
$inline
= 1;
$inline
= 0
if
$values_as_string
=~ m{\n};
$inline
= 0
if
length
(
$values_as_string
) > 40;
return
$values_as_string
if
$inline
;
my
@lines
= ();
push
@lines
,
'('
;
push
@lines
,
map
{
$self
->increase_indent(
$_
->pretty_print ) .
','
} @{
$self
->{
'items'
} };
$lines
[ -1 ] =~ s/,\z//;
push
@lines
,
')'
;
return
join
(
"\n"
,
@lines
);
}
1;