lib/Dancer2/Core/Types.pm

filter: Statementstmt 100% 33 / 33 Branchbran 100% 2 / 2 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 9 / 9 Podpod n/a totaltotal 95.9% 47 / 49 CC 3 SCAR 4.4
CC
3
Cov
97%
__ANON__
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.6
« blib/lib/Dancer2/FileUtils.pm ↑ Summary lib/Dancer2/Core.pm »
1 package Dancer2::Core::Types;
2 # ABSTRACT: Type::Tiny types for Dancer2 core.
3 264 $Dancer2::Core::Types::VERSION = '2.3.0';
4 264 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 264 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 264 ▶use Type::Library -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 264 ▶use Type::Utils -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 264 ▶use Sub::Quote 'quote_sub';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 264 ▶BEGIN { extends "Types::Standard" };
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 264 our %supported_http_methods = map +( $_ => 1 ), qw<
13 GET HEAD POST PUT DELETE OPTIONS PATCH QUERY
14 >;
15  
16 264 my $single_part = qr/
17 [A-Za-z] # must start with letter
18 (?: [A-Za-z0-9_]+ )? # can continue with letters, numbers or underscore
19 /x;
20  
21 264 my $namespace = qr/
22 ^
23 $single_part # first part
24 (?: (?: \:\: $single_part )+ )? # optional part starting with double colon
25 $
26 /x;
27  
28 264 declare 'ReadableFilePath', constraint => quote_sub q{ -e $_ && -r $_ };
29  
30 264 declare 'WritableFilePath', constraint => quote_sub q{ -e $_ && -w $_ };
31  
32 50 ▶declare 'Dancer2Prefix', as 'Str', where {
Subroutine __ANON__: called CC=1 SCAR=0.0
33 # a prefix must start with the char '/'
34 # index is much faster than =~ /^\//
35 50 index($_, '/') == 0
36 264 };
37  
38 19 ▶declare 'Dancer2AppName', as 'Str', where {
Subroutine __ANON__: called CC=1 SCAR=0.0
39 # TODO need a real check of valid app names
40 19 $_ =~ $namespace;
41 17 ▶}, message {
Subroutine __ANON__: called CC=3 SCAR=11.1
42 17 ▶ sprintf("%s is not a Dancer2AppName",
Branch: 1 branch
BranchTrueFalseTotal
$_ && length $_ ? : 14 3 17
Condition66%2/3
$_ and length $_
!ll&&!rl&&r
3014
MC/DC50%1/2
$_ and length $_
$_ length $_
Truth table66%2/3
A and B
A= $_B= length $_
ABresult
0X0
100
111
43 ($_ && length($_)) ? $_ : 'Empty string')
44 264 };
45  
46 264 declare 'Dancer2Method', as Enum [map +(lc), keys %supported_http_methods];
47  
48 264 declare 'Dancer2HTTPMethod', as Enum [keys %supported_http_methods];
49  
50 # generate abbreviated class types for core dancer objects
51 264 for my $type (
52 qw/
53 App
54 Context
55 Cookie
56 DSL
57 Dispatcher
58 Error
59 Hook
60 MIME
61 Request
62 Response
63 Role
64 Route
65 Runner
66 Server
67 Session
68 Types
69 /
70 )
71 {
72 4224 declare $type,
73 as InstanceOf[ 'Dancer2::Core::' . $type ];
74 }
75  
76 # Export everything by default.
77 264 our @EXPORT = __PACKAGE__->type_names;
78  
79 264 1;
80  
81 __END__
« blib/lib/Dancer2/FileUtils.pm ↑ Summary lib/Dancer2/Core.pm »