lib/App/GitFind/Class.pm

filter: Statementstmt 75.7% 25 / 33 Branchbran 50.0% 5 / 10 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 65.5% 40 / 61 CC 9 SCAR 25.7
CC
9
Cov
65%
_app_gitfind_class_builder_internal
21.1
BEGIN
1.0
BEGIN
1.0
CRAP 13.1
« lib/App/GitFind/FileProcessor.pm ↑ Summary lib/App/GitFind/Searcher/FileSystem.pm »
1 # App::GitFind::Class - Class::Tiny base class supporting new(-arg => value)
2 package App::GitFind::Class;
3  
4 2 ▶use 5.010;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use App::GitFind::Base;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 our $VERSION = '0.000002';
10  
11 # No parent, so Class::Tiny will become the parent
12 2 ▶use Class::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # Docs {{{1
15  
16 =head1 NAME
17  
18 App::GitFind::Class - Class::Tiny base class supporting new(-arg => value)
19  
20 =head1 SYNOPSIS
21  
22 This is the same as L<Class::Tiny> except for a custom C<BUILDARGS()> method
23 that permits you to put hyphens in front of the argument names in the
24 constructor call. This provides consistency with L<Getargs::Mixed>.
25  
26 =cut
27  
28 # }}}1
29  
30 =head1 FUNCTIONS
31  
32 =head2 BUILDARGS
33  
34 Pre-process the constructor arguments to strip leading hyphens from
35 argument names.
36  
37 Note: L<Class::Tiny> prohibits attributes named C<-> (a single hyphen),
38 so we don't handle that case.
39  
40 =cut
41  
42 # The internal builder, so I don't have to worry about dispatch
43 # once our BUILDARGS is called.
44  
45 1 ▶sub _app_gitfind_class_builder_internal {
Subroutine _app_gitfind_class_builder_internal: called CC=9 SCAR=30.5
46 1 ▶ my $class = shift or require Carp, Carp::croak 'Need a class';
Branch: 1 branch
BranchTrueFalseTotal
my $class = shift() or require Carp, Carp::croak("Need a class") 1 0 1
47  
48 1 ▶ if(@_ == 1 && ref $_[0] eq 'HASH') {
Branch: 3 branches
BranchTrueFalseTotal
if (@_ == 1 and ref $_[0] eq 'HASH') { } 0 1 1
elsif (@_ == 1 and ref $_[0]) { } 0 1 1
elsif (@_ % 2) { } 0 1 1
Condition33%1/3
@_ == 1 and ref $_[0] eq "HASH"
!ll&&!rl&&r
100
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1 ref $_[0] eq "HASH"
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
ABresult
0X0
100
111
49 0 @_ = ($class, %{$_[0]});
50 0 goto \&_app_gitfind_class_builder_internal;
51 # No extra stack frame for the sake of croak()
52 ▶ } elsif(@_ == 1 && ref $_[0]) {
Condition33%1/3
@_ == 1 and ref $_[0]
!ll&&!rl&&r
100
MC/DC0%0/2
@_ == 1 and ref $_[0]
@_ == 1 ref $_[0]
Truth table33%1/3
A and B
A= @_ == 1B= ref $_[0]
ABresult
0X0
100
111
53 0 require Carp;
54 0 Carp::croak "$class\->new(arg) with @{[ref $_[0]]} instead of HASH ref";
55 } elsif(@_ % 2) {
56 0 require Carp;
57 0 Carp::croak "Odd number of arguments to $class\->new()";
58 }
59  
60 # Now we have key-value pairs. Trim leading hyphens on the keys.
61 1 my %args = @_;
62 1 for (keys %args) {
63 2 ▶ next unless /^-/;
Branch: 1 branch
BranchTrueFalseTotal
unless /^-/ 0 2 2
64 2 $args{ substr $_, 1 } = $args{ $_ };
65 2 delete $args{ $_ };
66 }
67  
68 1 return \%args;
69 }; # $_builder()
70  
71 1 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=1 SCAR=0.0
Pod documented
72 1 goto \&App::GitFind::Class::_app_gitfind_class_builder_internal;
73 } #BUILDARGS()
74  
75 2 1;
76 __END__
« lib/App/GitFind/FileProcessor.pm ↑ Summary lib/App/GitFind/Searcher/FileSystem.pm »