### 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; }