blib/lib/App/iTan/Command/List.pm

filter: Statementstmt 53.1% 17 / 32 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 75.0% 6 / 8 Podpod n/a totaltotal 50.0% 23 / 46 CC 4 SCAR 20.8
CC
4
Cov
45%
get_table
20.0
execute
2.0
BEGIN
1.0
CRAP 8.0
« blib/lib/App/iTan/Command/Info.pm ↑ Summary blib/lib/App/iTan/Command/Delete.pm »
1 # ================================================================
2 package App::iTan::Command::List;
3 # ================================================================
4 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use 5.0100;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use MooseX::App::Command;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 with qw(App::iTan::Utils);
10  
11 1 ▶use Text::Table;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Moose::Util::TypeConstraints qw(enum);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 our @SORTFIELDS = qw(tindex imported used);
15  
16 option 'sort' => (
17 is => 'ro',
18 isa => enum(\@SORTFIELDS),
19 required => 1,
20 default => $SORTFIELDS[0],
21 documentation => q[Set list sorting (].(join ',',@SORTFIELDS).q[)],
22 );
23  
24 0 ▶sub execute {
Subroutine execute: not called CC=1 SCAR=6.9
25 0 my ( $self, $opts, $args ) = @_;
26  
27 0 my $tb = $self->get_table();
28  
29 0 print $tb->title;
30 0 print $tb->rule('-','+');
31 0 print $tb->body;
32  
33 0 return;
34 }
35  
36 0 ▶sub get_table {
Subroutine get_table: not called CC=4 SCAR=30.0
37 0 my ($self) = @_;
38  
39 0 my $sort = $self->sort;
40 0 ▶ $sort .= ','.$SORTFIELDS[0]
Branch: 1 branch
BranchTrueFalseTotal
unless $App::iTan::Command::List::SORTFIELDS[0] eq $sort 0 0 0
41 unless $SORTFIELDS[0] eq $sort;
42 0 ▶ my $sth = $self->dbh->prepare("SELECT tindex,imported,used,memo
Branch: 1 branch
BranchTrueFalseTotal
my $sth = $self->dbh->prepare("SELECT tindex,imported,used,memo\n FROM itan\n WHERE valid = 1 OR used IS NOT NULL\n ORDER BY $sort") or die 'ERROR: Cannot prepare: ' . $self->dbh->errstr 0 0 0
43 FROM itan
44 WHERE valid = 1 OR used IS NOT NULL
45 ORDER BY $sort")
46 or die "ERROR: Cannot prepare: " . $self->dbh->errstr();
47 0 $sth->execute();
48  
49 0 my $tb = Text::Table->new(
50 "Index",\"|","Imported",\"|","Used",\"|","Memo"
51 );
52  
53 0 ▶ while (my @line = $sth->fetchrow_array) {
Branch: 1 branch
BranchTrueFalseTotal
if (my(@line) = $sth->fetchrow_array) 0 0 0
54 0 $tb->add(@line);
55 }
56  
57 0 return $tb;
58 }
59  
60 __PACKAGE__->meta->make_immutable;
61 1;
62  
63 =pod
64  
65 =encoding utf8
66  
67 =head1 NAME
68  
69 App::iTan::Command::List - List of all iTANs
70  
71 =head1 SYNOPSIS
72  
73 itan list [--sort (tindex imported used)]
74  
75 =head1 DESCRIPTION
76  
77 List of all either used or still available iTANs.
78  
79 =head1 OPTIONS
80  
81 =head2 sort
82  
83 Set list sorting. Available options are
84  
85 =over
86  
87 =item * tindex
88  
89 =item * imported
90  
91 =item * used
92  
93 =back
94  
95 =cut
« blib/lib/App/iTan/Command/Info.pm ↑ Summary blib/lib/App/iTan/Command/Delete.pm »