App-GUI-Juliagraph

 view release on metacpan or  search on metacpan

lib/App/GUI/Juliagraph/Settings.pm  view on Meta::CPAN


package App::GUI::Juliagraph::Settings;
use v5.12;
use warnings;
use FindBin;
use File::Spec;

sub load {
    my ($file) = @_;
    return unless defined $file;
    $file = expand_path( $file );
    my $data = {};
    open my $FH, '<', $file or return "could not read $file: $!";
    my $cat = '';
    while (<$FH>) {
        chomp;
        next unless $_ or substr( $_, 0, 1) eq '#';
        if    (/\s*\[(\w+)\]/)           { $cat = $1 }
        elsif (/\s*(\w+)\s*=\s*(.+)\s*$/){ $data->{$cat}{$1} = $2 }
    }
    close $FH;

lib/App/GUI/Juliagraph/Settings.pm  view on Meta::CPAN


sub shrink_path {
    my ($path)  = @_;
    my $i = index($path, $FindBin::Bin );
    $path = '.' . substr( $path, length $FindBin::Bin) if $i > -1;
    $i = index($path, $ENV{HOME} );
    $path = '~' . substr( $path, length $ENV{HOME}) if $i > -1;
    $path;
}

sub expand_path {
    my ($path)  = @_;
    $path = File::Spec->catdir( $FindBin::Bin, substr( $path, 1) ) if substr($path, 0,1) eq '.';
    $path = File::Spec->catdir( $ENV{HOME}, substr( $path, 1) ) if substr($path, 0,1) eq '~';
    $path;
}


sub are_equal {
    my ($h1, $h2)  = @_;
    return 0 unless ref $h1 eq 'HASH' and ref $h2 eq 'HASH';



( run in 0.558 second using v1.01-cache-2.11-cpan-5623c5533a1 )