TeamCity/LocatorSpec.pm

filter: Statementstmt 100% 62 / 62 Branchbran 94.4% 17 / 18 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 12 / 12 Podpod n/a totaltotal 96.9% 94 / 97 CC 12 SCAR 16.4
CC
12
Cov
98%
locator_string_for_args
10.0
as_dict
3.0
BEGIN
1.0
CRAP 5.2
↑ Summary TeamCity/Inflator.pm »
1 package WebService::TeamCity::LocatorSpec;
2  
3 4 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 our $VERSION = '0.04';
9  
10 4 ▶use Type::Params qw( compile );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Types::Standard qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
12 ArrayRef
13 Bool
14 Dict
15 HashRef
16 Int
17 Optional
18 Str
19 slurpy
20 4 );
21 4 ▶use String::CamelSnakeKebab qw( lower_camel_case );
Subroutine BEGIN: called CC=1 SCAR=0.0
22 4 ▶use WebService::TeamCity::Types qw( DateTimeObject JSONBool );
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 4 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
25  
26 4 has name => (
27 is => 'ro',
28 isa => Str,
29 required => 1,
30 );
31  
32 4 has type_spec => (
33 is => 'ro',
34 isa => HashRef,
35 required => 1,
36 );
37  
38 2 ▶sub validator {
Subroutine validator: called CC=1 SCAR=0.0
39 2 my $self = shift;
40 2 return compile( slurpy $self->as_dict(@_) );
41 }
42  
43 4 my %PagingArgs = (
44 count => Int,
45 start => Int,
46 );
47  
48 36 ▶sub as_dict {
Subroutine as_dict: called CC=3 SCAR=11.0
49 36 my $self = shift;
50 36 my %args = @_;
51  
52 my %spec
53 = $args{include_paging_args}
54 2 ? ( %{ $self->type_spec }, %PagingArgs )
55 36 ▶ : %{ $self->type_spec };
Branch: 1 branch
BranchTrueFalseTotal
$args{'include_paging_args'} ? : 2 34 36
56  
57 return Dict [
58 map {
59 36 $_ => Optional [
60 $spec{$_}->isa('WebService::TeamCity::LocatorSpec')
61 ? $spec{$_}->as_dict
62 170 ▶ : $spec{$_}
Branch: 1 branch
BranchTrueFalseTotal
$spec{$_}->isa('WebService::TeamCity::LocatorSpec') ? : 34 136 170
63 ]
64 }
65 keys %spec
66 ];
67 }
68  
69 9 ▶sub locator_string_for_args {
Subroutine locator_string_for_args: called CC=10 SCAR=23.0
70 9 my $self = shift;
71 9 my %args = @_;
72  
73 9 ▶ return unless $args{search_args} && keys %{ $args{search_args} };
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"search_args"} and keys %{$args{"search_args"};} 1 8 9
Condition66%2/3
$args{"search_args"} and keys %{$args{"search_args"};}
!ll&&!rl&&r
018
MC/DC50%1/2
$args{"search_args"} and keys %{$args{"search_args"};}
$args{"search_args"} keys %{$args{"search_args"};}
Truth table66%2/3
A and B
A= $args{"search_args"}B= keys %{$args{"search_args"};}
ABresult
0X0
100
111
74  
75 my %spec
76 = $args{include_paging_args}
77 5 ? ( %{ $self->type_spec }, %PagingArgs )
78 8 ▶ : %{ $self->type_spec };
Branch: 1 branch
BranchTrueFalseTotal
$args{'include_paging_args'} ? : 5 3 8
79  
80 8 my @l;
81 8 for my $key (
82 24 sort { $a cmp $b }
83 111 grep { exists $args{search_args}{$_} } keys %spec
84 ) {
85  
86 17 my $type = $spec{$key};
87  
88 17 my $v;
89 ## no critic (ControlStructures::ProhibitCascadingIfElse)
90 17 ▶ if ( $type->isa(__PACKAGE__) ) {
Branch: 4 branches
BranchTrueFalseTotal
if ($type->isa(__PACKAGE__)) { } 3 14 17
elsif ($type->equals(&Bool() | &JSONBool())) { } 1 13 14
elsif ($type->is_subtype_of(&ArrayRef())) { } 2 11 13
elsif ($type->equals(&DateTimeObject())) { } 1 10 11
91 $v
92 = '('
93 . $type->locator_string_for_args(
94 3 search_args => $args{search_args}{$key} )
95 . ')';
96 }
97 elsif ( $type->equals( Bool | JSONBool ) ) {
98 1 ▶ $v = $args{search_args}{$key} ? 'true' : 'false';
Branch: 1 branch
BranchTrueFalseTotal
$args{'search_args'}{$key} ? : 1 0 1
99 }
100 elsif ( $type->is_subtype_of(ArrayRef) ) {
101 2 $v = '(' . ( join ',', @{ $args{search_args}{$key} } ) . ')';
102 }
103 elsif ( $type->equals(DateTimeObject) ) {
104 1 $v = $args{search_args}{$key}->strftime('%Y%m%dT%H%M%S%z');
105 }
106 else {
107 # Str, Int, etc.
108 10 $v = $args{search_args}{$key};
109 }
110  
111 17 push @l, join ':', lower_camel_case($key), $v;
112 }
113  
114 8 return join ',', @l;
115 }
116  
117 4 1;
118  
119 # ABSTRACT: Class to represent locator specifications
120  
121 __END__
↑ Summary TeamCity/Inflator.pm »