CLI/Argument/TypeTiny.pm

filter: Statementstmt 94.1% 16 / 17 Branchbran 50.0% 1 / 2 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 85.1% 23 / 27 CC 3 SCAR 8.1
CC
3
Cov
86%
validate
3.5
BEGIN
1.0
BEGIN
1.0
CRAP 2.2
« CLI/Argument/Enum.pm ↑ Summary CLI/L10N.pm »
1 #=============================================================================
2 #
3 # Module: Term::CLI::Argument::TypeTiny
4 #
5 # Description: Class for Type::Tiny validated arguments in Term::CLI
6 #
7 # Author: Diab Jerius (DJERIUS), <djerius@cpan.org>
8 # Created: 16/Apr/2022
9 #
10 # Copyright (c) 2022 Diab Jerius, Smithsonian Astrophysical Observatory
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::Argument::TypeTiny 0.061001;
22  
23 1 ▶use Types::Standard 1.000005 qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
24 Bool
25 InstanceOf
26 1 );
27  
28 1 ▶use Moo 1.000001;
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 1 ▶use namespace::clean 0.25;
Subroutine BEGIN: called CC=1 SCAR=0.0
31  
32 1 extends 'Term::CLI::Argument';
33  
34 1 has coerce => (
35 is => 'ro',
36 isa => Bool,
37 default => 0,
38 );
39  
40 1 has typetiny => (
41 is => 'ro',
42 isa => InstanceOf ['Type::Tiny'],
43 required => 1,
44 );
45  
46 2 ▶sub validate {
Subroutine validate: called CC=3 SCAR=12.5
Pod documented
47 2 my ( $self, $value ) = @_;
48  
49 2 ▶ $value = $self->typetiny->coerce( $value ) if $self->coerce;
Branch: 1 branch
BranchTrueFalseTotal
if $self->coerce 2 0 2
50 2 ▶ my $error = $self->typetiny->validate( $value ) // return $value;
Condition50%1/2
$self->typetiny->validate($value) // (return $value)
l!l
02
MC/DC0%0/1
$self->typetiny->validate($value) // (return $value)
$self->typetiny->validate($value)
Truth table50%1/2
A
A= $self->typetiny->validate($value)
Aresult
11
00
51 0 return $self->set_error( $error );
52 }
53  
54  
55 1 1;
56  
57 __END__
« CLI/Argument/Enum.pm ↑ Summary CLI/L10N.pm »