use
5.10.0;
use
Log::Any
'$log'
,
filter
=> \
&log_filter
;
our
$VERSION
=
'0.12'
;
$VERSION
=
eval
$VERSION
;
our
@EXPORT_OK
= (
qw(dumper log_filter get_icon_path)
);
sub
dumper {
Data::Dumper->new([
@_
])->Indent(1)->Sortkeys(1)->Terse(1)->Useqq(1)->Dump;
}
sub
log_filter {
my
(
$c
,
$l
) = (
shift
,
shift
);
my
%levels
= (
0
=>
'EMERGENCY'
,
1
=>
'ALERT'
,
2
=>
'CRITICAL'
,
3
=>
'ERROR'
,
4
=>
'WARNING'
,
5
=>
'NOTICE'
,
6
=>
'INFO'
,
7
=>
'DEBUG'
,
8
=>
'TRACE'
,
);
return
"[$levels{$l}]($c) @_"
;
}
sub
get_icon_path {
my
@args
=
@_
;
my
$icon_path
;
my
$filename
=
'chart-line-solid.png'
;
my
$distname
=
'App-financeta'
;
try
{
$icon_path
= dist_file(
$distname
,
$filename
);
}
catch
{
$log
->
warn
(
"Failed to find icon. Error: $_"
);
$icon_path
=
undef
;
};
unless
(
$icon_path
) {
my
$dist_share_path
= rel2abs(catfile(getcwd,
'share'
));
try
{
$log
->debug(
"icon backup dist-share path: $dist_share_path"
);
if
(
@args
) {
foreach
(
@args
) {
$File::ShareDir::DIST_SHARE
{
$_
} =
$dist_share_path
;
}
}
$File::ShareDir::DIST_SHARE
{
$distname
} =
$dist_share_path
;
$icon_path
= dist_file(
$distname
,
$filename
);
}
catch
{
$log
->
warn
(
"Failed to find icon in $dist_share_path. Error: $_"
);
$icon_path
=
undef
;
};
};
$log
->debug(
"Icon path: $icon_path"
)
if
defined
$icon_path
;
if
(
defined
$icon_path
and -e
$icon_path
) {
return
$icon_path
;
}
else
{
$log
->
warn
(
"No icon found, using system icon"
);
return
undef
;
}
}
1;