File Coverage

blib/lib/App/JobLog/Command/tags.pm
Criterion Covered Total %
statement 43 45 95.5
branch 14 16 87.5
condition 5 6 83.3
subroutine 9 11 81.8
pod 3 6 50.0
total 74 84 88.1


line stmt bran cond sub pod time code
1             package App::JobLog::Command::tags;
2             $App::JobLog::Command::tags::VERSION = '1.039';
3             # ABSTRACT: show what tags you have used
4              
5 2     2   1923 use App::JobLog -command;
  2         6  
  2         16  
6 2     2   772 use Modern::Perl;
  2         4  
  2         13  
7 2     2   228 use Class::Autouse qw(App::JobLog::Log);
  2         4  
  2         21  
8 2     2   95 use autouse 'App::JobLog::TimeGrammar' => qw(parse);
  2         3  
  2         11  
9 2     2   134 use autouse 'Getopt::Long::Descriptive' => qw(prog_name);
  2         3  
  2         13  
10              
11             sub execute {
12 9     9 1 111 my ( $self, $opt, $args ) = @_;
13              
14 9         18 my $events = [];
15 9         13 eval {
16 9 100       27 if (@$args)
17             {
18 6         38 my ( $start, $end ) = parse( join( ' ', @$args ) );
19 6 100       29 $events = App::JobLog::Log->new->find_events( $start, $end )
20             unless $opt->notes;
21             push @$events,
22 6 100 100     390 @{ App::JobLog::Log->new->find_notes( $start, $end ) }
  4         194  
23             unless !( $opt->notes || $opt->all );
24             }
25             else {
26 3         7 my $method = 'all_events';
27 3 100       10 if ( $opt->notes ) {
    100          
28 1         6 $method = 'all_notes';
29             }
30             elsif ( $opt->all ) {
31 1         11 $method = 'all_taglines';
32             }
33 3         33 $events = App::JobLog::Log->new->$method;
34             }
35             };
36 9 50       147 $self->usage_error($@) if $@;
37 9         494 my %tags;
38 9         27 for my $e (@$events) {
39 8         14 $tags{$_} = 1 for @{ $e->tags };
  8         34  
40             }
41 9 100       30 if (%tags) {
42 7         39 print "\n";
43 7         132 say $_ for sort keys %tags;
44 7         110 print "\n";
45             }
46             else {
47 2         13 say 'no tags in log';
48             }
49             }
50              
51 9     9 1 16149 sub usage_desc { '%c ' . __PACKAGE__->name . ' %o [date or date range]' }
52              
53             sub abstract {
54 0     0 1 0 'list tags employed in log or some subrange thereof';
55             }
56              
57             sub full_description {
58             <
59             List the tags used to categorize tasks or notes in the log or in a specified range of dates. This allows one to
60             explore the categorical structure of tasks and notes. By default only tags associated with notes are listed.
61              
62             The date expressions understood are the same as those understood by the C command.
63             END
64 0     0 0 0 }
65              
66             sub options {
67             return (
68             [
69 9     9 0 17 "Use '@{[prog_name]} help "
  9         26  
70             . __PACKAGE__->name
71             . '\' to see full details.'
72             ],
73             [ 'notes|n', 'only list tags used on notes' ],
74             [ 'all|a', 'list tags for both notes and tasks' ],
75             );
76             }
77              
78             sub validate {
79 9     9 0 24 my ( $self, $opt, $args ) = @_;
80 9 50 66     32 $self->usage_error('--notes conflicts will --all')
81             if $opt->notes && $opt->all;
82             }
83              
84             1;
85              
86             __END__