#!perl

our $DATE = '2014-07-18'; # DATE
our $VERSION = '0.02'; # VERSION

use 5.010;
use strict;
use warnings;

our %SPEC;

$SPEC{add} = {
    v => 1.1,
    summary => 'A function to add to ints',
    description => <<'_',

Just a dummy description. Just a dummy description. Yup, just a dummy
description. Just a dummy description. Just a dummy description. Yeah, just a
dummy description. Just a dummy description.

_
    args => {
        arg1 => {
            schema => 'int*',
            req => 1,
            pos => 0,
            cmdline_aliases => { a=>{} },
        },
        arg2 => {
            schema => 'int*',
            req => 1,
            pos => 1,
            cmdline_aliases => { b=>{} },
        },
    },
};
sub add {
    my %args = @_;

    # we need to do validation ourselves because P::C::Lite currently doesn't do
    # it for us.
    my $a1 = $args{arg1}; defined($a1) or return [400, "Please specify arg1"];
    $a1 =~ /\A[+-]?\d+\z/ or return [400, "Invalid arg1 (not an int)"];
    my $a2 = $args{arg2}; defined($a2) or return [400, "Please specify arg2"];
    $a2 =~ /\A[+-]?\d+\z/ or return [400, "Invalid arg2 (not an int)"];

    [200, "OK", $a1 + $a2];
}

$SPEC{subtract} = {
    v => 1.1,
    summary => 'A function to subtract to ints',
    description => <<'_',

This function also has result_naked and args_as set to array.

_
    args => {
        arg1 => {
            schema => 'int*',
            req => 1,
            pos => 0,
            cmdline_aliases => { a=>{} },
        },
        arg2 => {
            schema => 'int*',
            req => 1,
            pos => 1,
            cmdline_aliases => { b=>{} },
        },
    },
    # not yet supported by P::C::Lite
    #args_as => 'array',
    result_naked => 1,
};
sub subtract {
    my %args = @_;

    # we need to do validation ourselves because P::C::Lite currently doesn't do
    # it for us.
    my $a1 = $args{a1}; defined($a1) or die [400, "Please specify arg1"];
    $a1 =~ /\A[+-]?\d+\z/ or die [400, "Invalid arg1 (not an int)"];
    my $a2 = $args{a2}; defined($a2) or die [400, "Please specify arg2"];
    $a2 =~ /\A[+-]?\d+\z/ or die [400, "Invalid arg2 (not an int)"];

    $a1 - $a2;
}

use Perinci::CmdLine::Any;
Perinci::CmdLine::Any->new(
    url          => '/main/',
    subcommands  => {
        add      => {url => '/main/add'},
        subtract => {url => '/main/subtract'},
    },
)->run;

# ABSTRACT: Test command with multiple subcommands
# PODNAME: peri-eg-any-multi

__END__

=pod

=encoding UTF-8

=head1 NAME

peri-eg-any-multi - Test command with multiple subcommands

=head1 VERSION

This document describes version 0.02 of peri-eg-any-multi (from Perl distribution Perinci-Examples-Bin-Any), released on 2014-07-18.

=head1 SYNOPSIS

=head1 HOMEPAGE

Please visit the project's homepage at L<https://metacpan.org/release/Perinci-Examples-Bin-Any>.

=head1 SOURCE

Source repository is at L<https://github.com/sharyanto/perl-Perinci-Examples-Bin-Any>.

=head1 BUGS

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

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

Steven Haryanto <stevenharyanto@gmail.com>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2014 by Steven Haryanto.

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
