HiD/App/Command.pm

filter: Statementstmt 89.5% 43 / 48 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 91.6% 11 / 12 Podpod 100% 2 / 2 totaltotal 86.7% 59 / 68 CC 4 SCAR 7.3
CC
4
Cov
85%
reset_hid
6.0
execute
3.1
BEGIN
1.0
CRAP 2.1
« HiD/App/Command/init.pm ↑ Summary HiD/Generator.pm »
1 # ABSTRACT: Base class for HiD commands
2  
3  
4 package HiD::App::Command;
5 9 our $AUTHORITY = 'cpan:GENEHACK';
6 9 $HiD::App::Command::VERSION = '1.96';
7 9 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 9 extends 'MooseX::App::Cmd::Command';
9 9 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 9 ▶use 5.014; # strict, unicode_strings
Subroutine BEGIN: called CC=1 SCAR=0.0
12 9 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 9 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 9 ▶use warnings qw/ FATAL utf8 /;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 9 ▶use open qw/ :std :utf8 /;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 9 ▶use charnames qw/ :full /;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 9 ▶use HiD;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20  
21 9 has config_file => (
22 is => 'ro' ,
23 isa => 'Str' ,
24 cmd_aliases => 'f' ,
25 traits => [ qw/ Getopt / ] ,
26 default => '_config.yml' ,
27 );
28  
29 9 has hid => (
30 is => 'ro' ,
31 isa => 'HiD' ,
32 lazy => 1 ,
33 traits => [ qw/ NoGetopt/ ] ,
34 init_arg => undef ,
35 clearer => '_clear_hid' ,
36 predicate => '_has_hid' ,
37 builder => '_build_hid' ,
38 handles => [
39 'all_objects' ,
40 'config' ,
41 'destination' ,
42 'publish' ,
43 ] ,
44 );
45  
46 19 ▶sub _build_hid { HiD->new( shift->hid_config ) }
Subroutine _build_hid: called CC=1 SCAR=0.0
47  
48 9 has hid_config => (
49 is => 'ro' ,
50 isa => 'HashRef' ,
51 traits => [ qw/ NoGetopt / ] ,
52 init_arg => undef ,
53 writer => '_set_hid_config' ,
54 );
55  
56 sub execute {
57 22 ▶ my( $self , $opts , $args ) = @_;
Subroutine execute: called CC=3 SCAR=11.3
Pod documented
58  
59 22 ▶ if ( $opts->{help_flag} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts->{"help_flag"}) 0 22 22
60 0 print $self->usage->text;
61 0 exit;
62 }
63  
64 22 my $hid_config = { cli_opts => $opts };
65 22 ▶ if ( $self->isa( 'HiD::App::Command::init')) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isa('HiD::App::Command::init')) { } 3 19 22
66 $hid_config->{config} = {},
67 3 }
68 else {
69 19 $hid_config->{config_file} = $self->config_file
70 }
71  
72 22 $self->_set_hid_config( $hid_config );
73  
74 22 $self->_run( $opts , $args );
75 }
76  
77  
78 sub reset_hid {
79 0 ▶ my( $self ) = @_;
Subroutine reset_hid: not called CC=2 SCAR=17.9
Pod documented
80  
81 0 ▶ $self->_clear_hid() if $self->_has_hid();
Branch: 1 branch
BranchTrueFalseTotal
if $self->_has_hid 0 0 0
82  
83 0 return $self->hid();
84 }
85  
86 9 __PACKAGE__->meta->make_immutable;
87 9 1;
88  
89 __END__
90  
91 =pod
92  
93 =encoding UTF-8
94  
95 =head1 NAME
96  
97 HiD::App::Command - Base class for HiD commands
98  
99 =head1 SYNOPSIS
100  
101 package HiD::App::Command::my_awesome_command;
102 use Moose;
103 extends 'HiD::App::Command';
104  
105 sub _run {
106 my( $self , $opts , $args ) = @_;
107  
108 # do whatcha like
109 }
110  
111 1;
112  
113 =head1 DESCRIPTION
114  
115 Base class for implementing subcommands for L<hid>. Provides basic attributes
116 like C<--config_file>. If you're going to write a sub-command, you want to
117 base it on this class.
118  
119 =head1 ATTRIBUTES
120  
121 =head2 config_file
122  
123 Path to config file.
124  
125 Defaults to './_config.yml'
126  
127 =head1 METHODS
128  
129 =head2 reset_hid
130  
131 Clear out the existing L<HiD> object attribute, generate a fresh one with the
132 stored configuration information, and return it.
133  
134 =head1 VERSION
135  
136 version 1.96
137  
138 =head1 AUTHOR
139  
140 John SJ Anderson <genehack@genehack.org>
141  
142 =head1 COPYRIGHT AND LICENSE
143  
144 This software is copyright (c) 2015 by John SJ Anderson.
145  
146 This is free software; you can redistribute it and/or modify it under
147 the same terms as the Perl 5 programming language system itself.
148  
149 =cut
« HiD/App/Command/init.pm ↑ Summary HiD/Generator.pm »