| 1 | package Outthentic::Glue::Bash; | ||
| 2 | |||
| 3 | use base 'Exporter'; | ||
| 4 | use JSON; | ||
| 5 | use strict; | ||
| 6 | |||
| 7 | our @EXPORT = qw{ | ||
| 8 | json_var | ||
| 9 | }; | ||
| 10 | |||
| 11 | sub json_var { | ||
| 12 | |||
| 13 | my $path = $ARGV[0]; | ||
| 14 | my $name = $ARGV[1]; | ||
| 15 | |||
| 16 | open CONF, $path or die "can't open file $path to read: $!"; | ||
| 17 | my $data = join "", <CONF>; | ||
| 18 | close CONF; | ||
| 19 | |||
| 20 | my $json = JSON->new; | ||
| 21 | my $conf = $json->decode($data); | ||
| 22 | |||
| 23 | for my $n (split /\./, $name){ | ||
| 24 | $conf = $conf->{$n}; | ||
| 25 | } | ||
| 26 | |||
| 27 | if ( ref $conf eq "ARRAY") { | ||
| 28 | my $conf = join ' ', @$conf ; | ||
| 29 | print '(' . $conf . ')'; | ||
| 30 | } else { | ||
| 31 | print $conf; | ||
| 32 | } | ||
| 33 | |||
| 34 | } | ||
| 35 | |||
| 36 | 1; |