CLI/Base.pm

filter: Statementstmt 100% 36 / 36 Branchbran 100% 4 / 4 Conditioncond 100% 3 / 3 MC/DCmcdc 100% 2 / 2 Subroutinesub 100% 11 / 11 Podpod 100% 4 / 4 totaltotal 100% 60 / 60 CC 4 SCAR 4.5
CC
4
Cov
100%
set_error
3.0
root_node
2.0
BEGIN
1.0
CRAP 1.6
« CLI/Argument.pm ↑ Summary CLI/Argument/Number/Int.pm »
1 #=============================================================================
2 #
3 # Module: Term::CLI::Base
4 #
5 # Description: Generic base class for Term::CLI classes
6 #
7 # Author: Steven Bakker (SBAKKER), <sbakker@cpan.org>
8 # Created: 10/02/18
9 #
10 # Copyright (c) 2018-2022 Steven Bakker
11 #
12 # This module is free software; you can redistribute it and/or modify
13 # it under the same terms as Perl itself. See "perldoc perlartistic."
14 #
15 # This software is distributed in the hope that it will be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 #
19 #=============================================================================
20  
21 package Term::CLI::Base 0.061000;
22  
23 20 ▶use 5.014;
Subroutine BEGIN: called CC=1 SCAR=0.0
24 20 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 20 ▶use Term::CLI::ReadLine;
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 20 use Types::Standard 1.000005 qw(
29 Str
30 Maybe InstanceOf
31 20 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 20 ▶use Moo 1.000001;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 20 ▶use namespace::clean 0.25;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 20 has name => ( is => 'ro', isa => Str, required => 1 );
37 104 ▶has error => ( is => 'rwp', isa => Str, default => sub {q{}} );
Subroutine __ANON__: called CC=1 SCAR=0.0
38  
39 20 has parent => (
40 is => 'rwp',
41 week_ref => 1,
42 isa => Maybe[ InstanceOf['Term::CLI::Element'] ],
43 );
44  
45 sub root_node {
46 241 ▶ my ($self) = my ($curr_node) = @_;
Subroutine root_node: called CC=2 SCAR=6.9
Pod documented
47  
48 241 ▶ while ( my $parent = $curr_node->parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent = $curr_node->parent) 6 241 247
49 6 $curr_node = $parent;
50 }
51 241 return $curr_node;
52 }
53  
54 127 ▶sub term { return Term::CLI::ReadLine->term }
Subroutine term: called CC=1 SCAR=0.0
Pod documented
55  
56 sub clear_error {
57 82 ▶ my ($self) = @_;
Subroutine clear_error: called CC=1 SCAR=0.0
Pod documented
58 82 $self->_set_error(q{});
59 82 return 1;
60 }
61  
62 sub set_error {
63 78 ▶ my ( $self, @value ) = @_;
Subroutine set_error: called CC=3 SCAR=11.0
Pod documented
64 78 ▶ if ( !@value || !defined $value[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@value and defined $value[0]) 2 76 78
Condition100%3/3
@value and defined $value[0]
!ll&&!rl&&r
1176
MC/DC100%2/2
@value and defined $value[0]
@value defined $value[0]
Truth table100%3/3
A and B
A= @valueB= defined $value[0]
ABresult
0X0
100
111
65 2 $self->clear_error(q{});
66 return
67 2 }
68 76 $self->_set_error( join( q{}, @value ) );
69 76 return;
70 }
71  
72 20 1;
73  
74 __END__
75  
76 =pod
77  
78 =head1 NAME
79  
80 Term::CLI::Base - generic base class for Term::CLI classes
81  
82 =head1 VERSION
83  
84 version 0.061000
85  
86 =head1 SYNOPSIS
87  
88 package Term::CLI::Something {
89  
90 use Moo;
91  
92 extends 'Term::CLI::Base';
93  
94 ...
95 };
96  
97 =head1 DESCRIPTION
98  
99 Generic base class for L<Term::CLI>(3p) classes. This class provides some
100 basic functions and attributes that all classes except L<Term::CLI::ReadLine>
101 share.
102  
103 =head1 METHODS
104  
105 =head2 Accessors
106  
107 =over
108  
109 =item B<error>
110  
111 Contains a diagnostic message in case of errors.
112  
113 =item B<name>
114  
115 Element name. Can be any string, but must be specified at construction
116 time.
117  
118 =item B<term>
119  
120 The active L<Term::CLI::ReadLine> object.
121  
122 =back
123  
124 =head2 Others
125  
126 =over
127  
128 =item B<clear_error>
129  
130 Set the L<error|/error>() attribute to the empty string and return 1.
131  
132 =item B<parent>
133 X<parent>
134  
135 Return a reference to the object that "owns" this object.
136 This is will be an instance of a class that inherits from
137 C<Term::CLI::Element>, or C<undef>.
138  
139 =item B<root_node>
140 X<root_node>
141  
142 Walks the L<parent|/parent> chain until it can go no further.
143 Returns a reference to the object at the top. In a functional
144 setup this is expected to be a
145 L<Term::CLI|Term::CLI>(3p) object instance.
146  
147 =item B<set_error> ( I<STRING>, ... )
148  
149 Sets the L<error|/error>() attribute to the concatenation of all I<STRING>
150 parameters. If no arguments are given, or the first argument is C<undef>,
151 the error field is cleared (see L<set_error|/set_error> below).
152  
153 Always returns a "failure" (C<undef> or the empty list, depending on
154 call context).
155  
156 =back
157  
158 =head1 SEE ALSO
159  
160 L<Term::CLI>(3p),
161 L<Term::CLI::Element>(3p),
162 L<Term::CLI::ReadLine>(3p).
163  
164 =head1 AUTHOR
165  
166 Steven Bakker E<lt>sbakker@cpan.orgE<gt>, 2018.
167  
168 =head1 COPYRIGHT AND LICENSE
169  
170 Copyright (c) 2018 Steven Bakker
171  
172 This module is free software; you can redistribute it and/or modify
173 it under the same terms as Perl itself. See "perldoc perlartistic."
174  
175 This software is distributed in the hope that it will be useful,
176 but WITHOUT ANY WARRANTY; without even the implied warranty of
177 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
178  
179 =cut
« CLI/Argument.pm ↑ Summary CLI/Argument/Number/Int.pm »