### file: trig_calc1.pl
#!/usr/bin/env perl
use strict;
use warnings;
our %SPEC;
$SPEC{trig_calc} = {
v => 1.1,
args => {
degree1 => {schema=>'int*', req=>1, pos=>0},
minute1 => {schema=>'int*', req=>1, pos=>1},
second1 => {schema=>'int*', req=>1, pos=>2},
op => {schema=>'str*', req=>1, pos=>3},
degree2 => {schema=>'int*', req=>1, pos=>4},
minute2 => {schema=>'int*', req=>1, pos=>5},
second2 => {schema=>'int*', req=>1, pos=>6},
},
args_as => 'array',
result_naked => 1,
};
sub trig_calc {
my ($d1, $m1, $s1, $op, $d2, $m2, $s2) = @_;
if ($op eq '+') {
my ($dr, $mr, $sr) = (0, 0, 0);
$sr += $s1 + $s2;
if ($sr >= 60) { $mr += int($sr/60); $sr = $sr % 60 }
$mr += $m1 + $m2;
if ($mr >= 60) { $dr += int($mr/60); $mr = $mr % 60 }
$dr += $d1 + $d2;
return [$dr, $mr, $sr];
} else {
die "Unknown operation '$op'";
}
}
if ($ENV{HARNESS_ACTIVE}) {
require Test::More; Test::More->import;
is_deeply(trig_calc(90, 35, 29, '+', 90, 24, 29), [180, 59, 58]);
is_deeply(trig_calc(90, 35, 29, '+', 90, 24, 31), [181, 0, 0]);
done_testing();
} else {
require Perinci::CmdLine::Any;
Perinci::CmdLine::Any->new(url => '/main/trig_calc')->run;
}
####
### file: trig_calc2.pl
#!/usr/bin/env perl
use strict;
use warnings;
our %SPEC;
$SPEC{trig_calc} = {
v => 1.1,
args => {
degree1 => {schema=>'int*', req=>1, pos=>0},
minute1 => {schema=>'int*', req=>1, pos=>1},
second1 => {schema=>'int*', req=>1, pos=>2},
op => {schema=>'str*', req=>1, pos=>3},
degree2 => {schema=>'int*', req=>1, pos=>4},
minute2 => {schema=>'int*', req=>1, pos=>5},
second2 => {schema=>'int*', req=>1, pos=>6},
},
args_as => 'array',
result_naked => 1,
examples => [
{
argv => [90, 35, 29, '+', 90, 24, 29],
result => [180, 59, 58],
},
{
argv => [90, 35, 29, '+', 90, 24, 31],
result => [181, 0, 0],
},
],
};
sub trig_calc {
my ($d1, $m1, $s1, $op, $d2, $m2, $s2) = @_;
if ($op eq '+') {
my ($dr, $mr, $sr) = (0, 0, 0);
$sr += $s1 + $s2;
if ($sr >= 60) { $mr += int($sr/60); $sr = $sr % 60 }
$mr += $m1 + $m2;
if ($mr >= 60) { $dr += int($mr/60); $mr = $mr % 60 }
$dr += $d1 + $d2;
return [$dr, $mr, $sr];
} else {
die "Unknown operation '$op'";
}
}
if ($ENV{HARNESS_ACTIVE}) {
require Test::More; Test::More->import;
require Test::Rinci; Test::Rinci->import;
metadata_in_module_ok('main', {load=>0});
done_testing();
} else {
use Perinci::CmdLine::Any;
Perinci::CmdLine::Any->new(url => '/main/trig_calc')->run;
}
##
##
### file: lib/TrigCalc.pm
package TrigCalc;
use strict;
use warnings;
our %SPEC;
$SPEC{trig_calc} = {
v => 1.1,
args => {
degree1 => {schema=>'int*', req=>1, pos=>0},
minute1 => {schema=>'int*', req=>1, pos=>1},
second1 => {schema=>'int*', req=>1, pos=>2},
op => {schema=>'str*', req=>1, pos=>3},
degree2 => {schema=>'int*', req=>1, pos=>4},
minute2 => {schema=>'int*', req=>1, pos=>5},
second2 => {schema=>'int*', req=>1, pos=>6},
},
args_as => 'array',
result_naked => 1,
};
sub trig_calc {
my ($d1, $m1, $s1, $op, $d2, $m2, $s2) = @_;
if ($op eq '+') {
my ($dr, $mr, $sr) = (0, 0, 0);
$sr += $s1 + $s2;
if ($sr >= 60) { $mr += int($sr/60); $sr = $sr % 60 }
$mr += $m1 + $m2;
if ($mr >= 60) { $dr += int($mr/60); $mr = $mr % 60 }
$dr += $d1 + $d2;
return [$dr, $mr, $sr];
} else {
die "Unknown operation '$op'";
}
}
1;
##
##
### file: script/trig_calc
#!/usr/bin/env perl
use strict;
use warnings;
use TrigCalc;
use Perinci::CmdLine::Any;
Perinci::CmdLine::Any->new(url => '/TrigCalc/trig_calc')->run;
##
##
### file: t/trig_calc.t
#!perl
use strict;
use warnings;
use TrigCalc;
is_deeply(TrigCalc::trig_calc(90, 35, 29, '+', 90, 24, 29), [180, 59, 58]);
is_deeply(TrigCalc::trig_calc(90, 35, 29, '+', 90, 24, 31), [181, 0, 0]);
done_testing();