blib/lib/Types/Git.pm

filter: Statementstmt 100% 33 / 33 Branchbran 100% 6 / 6 Conditioncond 100% 27 / 27 MC/DCmcdc 100% 10 / 10 Subroutinesub 100% 12 / 12 Podpod n/a totaltotal 100% 88 / 88 CC 13 SCAR 17.5
CC
13
Cov
100%
__ANON__
11.0
__ANON__
2.0
__ANON__
2.0
CRAP 5.8
↑ Summary
1 package Types::Git;
2  
3 1 $Types::Git::VERSION = '0.04';
4  
5 =head1 NAME
6  
7 Types::Git - Type::Tiny types for git stuff.
8  
9 =head1 SYNOPSIS
10  
11 package Foo;
12
13 use Types::Git -types;
14
15 use Moo;
16 use strictures 1;
17 use namespace::clean;
18
19 has ref => (
20 is => 'ro',
21 isa => GitRef,
22 );
23  
24 =head1 DESCRIPTION
25  
26 This module provides several L<Type::Tiny> types for some of
27 git's data types.
28  
29 =cut
30  
31 1 ▶use Type::Library -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
32 1 ▶use Type::Utils -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use Types::Common::String -types;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use List::MoreUtils qw( any );
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 1 ▶use strictures 2;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 1 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 =head1 TYPES
40  
41 =head2 GitSHA
42  
43 A SHA1 hex, must be 40 characters or less long and contain
44 only hex characters.
45  
46 =cut
47  
48 my $GitSHA = declare 'GitSHA',
49 as NonEmptySimpleStr,
50 5 ▶ where {
Subroutine __ANON__: called CC=2 SCAR=6.9
51 5 ▶ length($_) <= 40 and
Branch: 1 branch
BranchTrueFalseTotal
length $_ <= 40 and $_ =~ /^[a-f0-9]+$/ 4 1 5
52 $_ =~ m{^[a-f0-9]+$}
53 1 };
54  
55 =head2 GitLooseRef
56  
57 Just like L</GitRef> except one-level refs (those without any forward slashes)
58 are allowed. This is useful for validating a branch or tag name.
59  
60 =cut
61  
62 my $GitLooseRef = declare 'GitLooseRef',
63 as NonEmptySimpleStr,
64 58 ▶ where {
Subroutine __ANON__: called CC=11 SCAR=24.0
65 # 1. They can include slash / for hierarchical (directory) grouping,
66 # but no slash-separated component can begin with a dot . or end
67 # with the sequence .lock.
68 58 ▶ ( ! any { $_ =~ m{^\.} or $_ =~ m{\.lock$} } split(/\//, $_) ) and
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 2 branches
BranchTrueFalseTotal
not &any(sub { $_ =~ /^\./ or $_ =~ /\.lock$/; } , split(m[/], $_, 0)) || $_ =~ /\.\./ || $_ =~ /[\000-\040\177 ~^:]/ || $_ =~ /[?*[]/ || $_ =~ m[^/] || $_ =~ m[/$] || $_ =~ m[//] || $_ =~ /\.$/ || $_ =~ /\@\{/ and $_ ne "\@" and not $_ =~ /\\/ 12 46 58
$_ =~ /^\./ or $_ =~ /\.lock$/ 6 148 154
Condition100%27/27
not &any(sub { $_ =~ /^\./ or $_ =~ /\.lock$/; } , split(m[/], $_, 0)) || $_ =~ /\.\./ || $_ =~ /[\000-\040\177 ~^:]/ || $_ =~ /[?*[]/ || $_ =~ m[^/] || $_ =~ m[/$] || $_ =~ m[//] || $_ =~ /\.$/ || $_ =~ /\@\{/ and $_ ne "\@"
!ll&&!rl&&r
44212
&any(sub { $_ =~ /^\./ or $_ =~ /\.lock$/; } , split(m[/], $_, 0)) || $_ =~ /\.\./ || $_ =~ /[\000-\040\177 ~^:]/ || $_ =~ /[?*[]/ || $_ =~ m[^/] || $_ =~ m[/$] || $_ =~ m[//] || $_ =~ /\.$/ || $_ =~ /\@\{/
l!l&&r!l&&!r
42214
&any(sub { $_ =~ /^\./ or $_ =~ /\.lock$/; } , split(m[/], $_, 0)) or $_ =~ /\.\./ or $_ =~ /[\000-\040\177 ~^:]/ or $_ =~ /[?*[]/ or $_ =~ m[^/] or $_ =~ m[/$] or $_ =~ m[//] or $_ =~ /\.$/
l!l&&r!l&&!r
40216
&any(sub { $_ =~ /^\./ or $_ =~ /\.lock$/; } , split(m[/], $_, 0)) or $_ =~ /\.\./ or $_ =~ /[\000-\040\177 ~^:]/ or $_ =~ /[?*[]/ or $_ =~ m[^/] or $_ =~ m[/$] or $_ =~ m[//]
l!l&&r!l&&!r
38218
&any(sub { $_ =~ /^\./ or $_ =~ /\.lock$/; } , split(m[/], $_, 0)) or $_ =~ /\.\./ or $_ =~ /[\000-\040\177 ~^:]/ or $_ =~ /[?*[]/ or $_ =~ m[^/] or $_ =~ m[/$]
l!l&&r!l&&!r
36220
&any(sub { $_ =~ /^\./ or $_ =~ /\.lock$/; } , split(m[/], $_, 0)) or $_ =~ /\.\./ or $_ =~ /[\000-\040\177 ~^:]/ or $_ =~ /[?*[]/ or $_ =~ m[^/]
l!l&&r!l&&!r
34222
&any(sub { $_ =~ /^\./ or $_ =~ /\.lock$/; } , split(m[/], $_, 0)) or $_ =~ /\.\./ or $_ =~ /[\000-\040\177 ~^:]/ or $_ =~ /[?*[]/
l!l&&r!l&&!r
28624
&any(sub { $_ =~ /^\./ or $_ =~ /\.lock$/; } , split(m[/], $_, 0)) or $_ =~ /\.\./ or $_ =~ /[\000-\040\177 ~^:]/
l!l&&r!l&&!r
141430
&any(sub { $_ =~ /^\./ or $_ =~ /\.lock$/; } , split(m[/], $_, 0)) or $_ =~ /\.\./
l!l&&r!l&&!r
12244
MC/DC100%10/10
not &any(sub { $_ =~ /^\./ or $_ =~ /\.lock$/; } , split(m[/], $_, 0)) || $_ =~ /\.\./ || $_ =~ /[\000-\040\177 ~^:]/ || $_ =~ /[?*[]/ || $_ =~ m[^/] || $_ =~ m[/$] || $_ =~ m[//] || $_ =~ /\.$/ || $_ =~ /\@\{/ and $_ ne "\@"
&any(sub { $_ =~ /^\./ or $_ =~ /\.lock$/; } , split(m[/], $_, 0)) $_ =~ /\.\./ $_ =~ /[\000-\040\177 ~^:]/ $_ =~ /[?*[]/ $_ =~ m[^/] $_ =~ m[/$] $_ =~ m[//] $_ =~ /\.$/ $_ =~ /\@\{/ $_ ne "\@"
Truth table100%11/11
not(A or B or C or D or E or F or G or H || I) and J
A= &any(sub { $_ =~ /^\./ or $_ =~ /\.lock$/; } , split(m[/], $_, 0))B= $_ =~ /\.\./C= $_ =~ /[\000-\040\177 ~^:]/D= $_ =~ /[?*[]/E= $_ =~ m[^/]F= $_ =~ m[/$]G= $_ =~ m[//]H= $_ =~ /\.$/I= $_ =~ /\@\{/J= $_ ne "\@"
ABCDEFGHIJresult
1XXXXXXXXX0
01XXXXXXXX0
001XXXXXXX0
0001XXXXXX0
00001XXXXX0
000001XXXX0
0000001XXX0
00000001XX0
000000001X0
00000000000
00000000011
69 # 3. They cannot have two consecutive dots .. anywhere.
70 $_ !~ m{\.\.} and
71 # 4. They cannot have ASCII control characters (i.e. bytes whose
72 # values are lower than \040, or \177 DEL), space, tilde ~, caret
73 # ^, or colon : anywhere.
74 $_ !~ m{[\000-\040\177 ~^:]} and
75 # 5. They cannot have question-mark ?, asterisk *, or open bracket [
76 # anywhere.
77 $_ !~ m{[?*[]} and
78 # 6. They cannot begin or end with a slash / or contain multiple
79 # consecutive slashes.
80 $_ !~ m{^/} and $_ !~ m{/$} and $_ !~ m{//} and
81 # 7. They cannot end with a dot ..
82 $_ !~ m{\.$} and
83 # 8. They cannot contain a sequence @{.
84 $_ !~ m{\@\{} and
85 # 9. They cannot be the single character @.
86 $_ ne '@' and
87 # 10. They cannot contain a \.
88 $_ !~ m{\\}
89 1 };
90  
91 =head2 GitRef
92  
93 Matches a ref against the same rules that
94 L<git-check-ref-format|http://git-scm.com/docs/git-check-ref-format> uses.
95  
96 =cut
97  
98 my $GitRef = declare 'GitRef',
99 as $GitLooseRef,
100 8 ▶ where {
Subroutine __ANON__: called CC=1 SCAR=0.0
101 # 2. They must contain at least one /.
102 8 $_ =~ m{/}
103 1 };
104  
105 =head2 GitBranchRef
106  
107 A L</GitRef> which begins with C<refs/heads/> and ends with a
108 L</GitLooseRef>.
109  
110 =cut
111  
112 declare 'GitBranchRef',
113 as $GitRef,
114 2 ▶ where { $_ =~ m{^refs/heads/} };
Subroutine __ANON__: called CC=1 SCAR=0.0
115  
116 =head2 GitTagRef
117  
118 A L</GitRef> which begins with C<refs/tags/> and ends with a
119 L</GitLooseRef>.
120  
121 =cut
122  
123 declare 'GitTagRef',
124 as $GitRef,
125 2 ▶ where { $_ =~ m{^refs/tags/} };
Subroutine __ANON__: called CC=1 SCAR=0.0
126  
127 =head2 GitObject
128  
129 This is a union type of L</GitSHA> and L</GitLooseRef>. In the future
130 this type may be expanded to include other types as more of
131 L<gitrevisions|http://git-scm.com/docs/gitrevisions> is incorporated
132 with this module.
133  
134 =cut
135  
136 1 my $GitObject = declare 'GitObject',
137 as $GitSHA | $GitLooseRef;
138  
139 =head2 GitRevision
140  
141 Currenlty this is an alias for L</GitObject> but may be extended in
142 the future to include other types as more of
143 L<gitrevisions|http://git-scm.com/docs/gitrevisions> is incorporated
144 with this module.
145  
146 This type is meant to be the same as L</GitObject> except with extended
147 rules for date ranges and such.
148  
149 =cut
150  
151 1 my $GitRevision = declare 'GitRevision',
152 as $GitObject;
153  
154 1 1;
155 __END__
↑ Summary