App-Dochazka-CLI
view release on metacpan or search on metacpan
get rid of unintuitive t/cmd_active/001-init.t
- use prompt date (century, year, month, etc.) instead of current date
(century, year, month, etc.)
- Test.pm: add a 'delete_interval' test routine
- t/cmd_active/interval.t: expand unit; use imported 'delete_interval' routine;
test that "PROMPT 2015-01-01" does change all the $prompt_... variables
0.186 2015-04-28 17:34 CEST
- t/util/: add two new units auth.t and determine_employee.t
- Util.pm: abolish 'quiet' parameter to authenticate_to_server and make routine
completely mute; validate a parameter; document routines better; refactor
authenticate_to_server for code readability and more reasonable return value;
lookup_employee: fix bugs uncovered by unit testing
- bin/dochazka-cli: move in authentication announcement from
authenticate_to_server
0.187 2015-04-29 19:47 CEST
- Util.pm, t/util/ts.t: more documentation improvement; remove deprecated
tsrange_from_timestamps routine; use $prompt_year instead of $current_year;
eliminate deprecated $current_{year,century,month} package variables
- CommandMap.pm, Parser.pm: move functions from CommandMap.pm to Parser.pm;
lib/App/Dochazka/CLI/Commands/Interval.pm view on Meta::CPAN
=head3 _interval_new
Takes code, tsrange and, optionally, long_desc. Converts the code into an AID,
sets up and sends the "POST interval/new" REST request, and returns the
resulting status object.
=cut
sub _interval_new {
my ( $code, $tsrange, $long_desc ) = validate_pos( @_,
{ type => SCALAR },
{ type => SCALAR },
{ type => SCALAR|UNDEF, optional => 1 },
);
# get aid from code
my $status = send_req( 'GET', "activity/code/$code" );
if ( $status->not_ok ) {
if ( $status->code eq "DISPATCH_SEARCH_EMPTY" and
$status->text =~ m/Search over activity with key -\>code equals .+\<- returned nothing/
lib/App/Dochazka/CLI/Commands/Interval.pm view on Meta::CPAN
}
EOS
return shared_generate_report( $entity );
}
=head3 _fillup
=cut
sub _fillup {
my ( %ARGS ) = validate( @_, {
eid => { type => SCALAR },
code => { type => SCALAR, optional => 1 },
date_list => { type => ARRAYREF, optional => 1 },
tsrange => { type => SCALAR, optional => 1 },
dry_run => { type => SCALAR },
clobber => { type => SCALAR, default => 1 },
} );
my $request_body = encode_json( \%ARGS );
lib/App/Dochazka/CLI/Util.pm view on Meta::CPAN
=head2 lookup_employee
EMPLOYEE_SPEC may be "nick=...", "sec_id=...", "eid=...", or simply
"employee=...", in which case we use a clever algorithm to look up employees
(i.e. try looking up search key as nick, sec_id, and EID - in that order).
=cut
sub lookup_employee {
my %ARGS = validate( @_,
{
key => { type => SCALAR },
minimal => { default => 0 },
}
);
print "Entering " . __PACKAGE__ . "::lookup_employee with search key " . Dumper( $ARGS{key} )
if $debug_mode;
die( "AH! Not an EMPLOYEE_SPEC" ) unless $ARGS{key} =~ m/=/;
lib/App/Dochazka/CLI/Util.pm view on Meta::CPAN
=item * single-digit forms
If a single-digit form is given, a leading zero is appended.
=item * seconds
If seconds are given, they are ignored.
=item * no validation
No attempt is made to validate the time -- this is done later, by
PostgreSQL.
=back
=cut
sub normalize_time {
my $rt = shift; # rt == raw time
return '00:00' unless $rt;
lib/App/Dochazka/CLI/Util.pm view on Meta::CPAN
=head2 truncate_to
Given a string and a maximum length (defaults to 32), truncates to that length.
Returns a copy of the string. If any characters were actually removed in the
truncate operation, '...' is appended -- unless the maximum length is zero, in
which case the empty string is returned.
=cut
sub truncate_to {
my ( $str, $mlen ) = validate_pos( @_,
{ type => SCALAR|UNDEF },
{
callbacks => {
'greater than or equal to zero' => sub { shift() >= 0 },
},
optional => 1,
type => SCALAR,
},
);
$mlen = 32 unless defined( $mlen );
( run in 0.241 second using v1.01-cache-2.11-cpan-4d50c553e7e )