#!perl

our $DATE = '2014-08-30'; # DATE
our $VERSION = '0.03'; # VERSION

use 5.010;
use strict;
use warnings;

use App::IODUtils;
use Perinci::CmdLine::Any -prefer_lite=>1;

our %SPEC;
$SPEC{get_iod_key} = {
    v => 1.1,
    summary => 'Get key value from IOD configration file',
    args => {
        %App::IODUtils::common_args,
        section => {
            schema  => 'str*',
            req     => 1,
            pos     => 1,
        },
        key => {
            schema  => 'str*',
            req     => 1,
            pos     => 2,
        },
    },
};
sub get_iod_key {
    my %args = @_;

    state $reader = do {
        require Config::IOD::Reader;
        Config::IOD::Reader->new(enable_expr=>$args{enable_expr});
    };

    my $hoh = $reader->read_string($args{iod});

    my $section = $args{section};
    my $key     = $args{key};

    return [404, "No such section"] unless exists $hoh->{$section};
    return [404, "No such key"] unless exists $hoh->{$section}{$key};

    [200, "OK", $hoh->{$section}{$key}];
}

Perinci::CmdLine::Any->new(
    url => '/main/get_iod_key',
)->run;

# ABSTRACT: Get key value from IOD configration file
# PODNAME: get-iod-key

__END__

=pod

=encoding UTF-8

=head1 NAME

get-iod-key - Get key value from IOD configration file

=head1 VERSION

This document describes version 0.03 of get-iod-key (from Perl distribution App-IODUtils), released on 2014-08-30.

=head1 SYNOPSIS

Basic usage:

 % get-iod-key /path/to/file.iod section key

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/App-IODUtils>.

=head1 SOURCE

Source repository is at L<https://github.com/perlancar/perl-App-IODUtils>.

=head1 BUGS

Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=App-IODUtils>

When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.

=head1 AUTHOR

perlancar <perlancar@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by perlancar@cpan.org.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut
