App-financeta

 view release on metacpan or  search on metacpan

lib/App/financeta/utils.pm  view on Meta::CPAN

package App::financeta::utils;
use strict;
use warnings;
use 5.10.0;
use Data::Dumper ();
use Exporter qw(import);
use Log::Any '$log', filter => \&log_filter;
use Try::Tiny;
use File::ShareDir 'dist_file';
use File::Spec::Functions qw(rel2abs catfile);
use Cwd qw(getcwd);

our $VERSION = '0.16';
$VERSION = eval $VERSION;
our @EXPORT_OK = (
    qw(dumper log_filter get_icon_path get_file_path)
);

sub dumper {
    Data::Dumper->new([@_])->Indent(1)->Sortkeys(1)->Terse(1)->Useqq(1)->Dump;
}

sub log_filter {
    my ($c, $l) = (shift, shift);
    ## copied from Log::Any::Adapter::Util
    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 {
    return get_file_path('chart-line-solid.png', @_);
}

sub get_file_path {
    my ($filename, @args) = @_;
    return unless defined $filename;
    my $file_path;
    my $distname = 'App-financeta';
    try {
        $file_path = dist_file($distname, $filename);
    } catch {
        $log->warn("Failed to find $filename. Error: $_");
        $file_path = undef;
    };
    unless ($file_path) {
        my $dist_share_path = rel2abs(catfile(getcwd, 'share'));
        try {
            $log->debug("$filename backup dist-share path: $dist_share_path");
            ## find all packages and search for all of them
            if (@args) {
                foreach (@args) {
                    $File::ShareDir::DIST_SHARE{$_} = $dist_share_path;
                }
            }
            $File::ShareDir::DIST_SHARE{$distname} = $dist_share_path;
            $file_path = dist_file($distname, $filename);
        } catch {
            $log->warn("Failed to find $filename in $dist_share_path. Error: $_");



( run in 0.887 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )