blib/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 blib/lib/Dancer2/Core.pm »
1 package Dancer2::Core::Types;
2 # ABSTRACT: Type::Tiny types for Dancer2 core.
3 256 $Dancer2::Core::Types::VERSION = '2.2.1';
4 256 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 256 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 256 ▶use Type::Library -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 256 ▶use Type::Utils -all;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 256 ▶use Sub::Quote 'quote_sub';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 256 ▶BEGIN { extends "Types::Standard" };
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 256 our %supported_http_methods = map +( $_ => 1 ), qw<
13 GET HEAD POST PUT DELETE OPTIONS PATCH
14 >;
15  
16 256 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 256 my $namespace = qr/
22 ^
23 $single_part # first part
24 (?: (?: \:\: $single_part )+ )? # optional part starting with double colon
25 $
26 /x;
27  
28 256 declare 'ReadableFilePath', constraint => quote_sub q{ -e $_ && -r $_ };
29  
30 256 declare 'WritableFilePath', constraint => quote_sub q{ -e $_ && -w $_ };
31  
32 declare 'Dancer2Prefix', as 'Str', where {
33 # a prefix must start with the char '/'
34 # index is much faster than =~ /^\//
35 50 ▶ index($_, '/') == 0
Subroutine __ANON__: called CC=1 SCAR=0.0
36 256 };
37  
38 declare 'Dancer2AppName', as 'Str', where {
39 # TODO need a real check of valid app names
40 19 ▶ $_ =~ $namespace;
Subroutine __ANON__: called CC=1 SCAR=0.0
41 }, message {
42 17 ▶ sprintf("%s is not a Dancer2AppName",
Subroutine __ANON__: called CC=3 SCAR=11.1
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 256 };
45  
46 256 declare 'Dancer2Method', as Enum [map +(lc), keys %supported_http_methods];
47  
48 256 declare 'Dancer2HTTPMethod', as Enum [keys %supported_http_methods];
49  
50 # generate abbreviated class types for core dancer objects
51 256 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 4096 declare $type,
73 as InstanceOf[ 'Dancer2::Core::' . $type ];
74 }
75  
76 # Export everything by default.
77 256 our @EXPORT = __PACKAGE__->type_names;
78  
79 256 1;
80  
81 __END__
« blib/lib/Dancer2/FileUtils.pm ↑ Summary blib/lib/Dancer2/Core.pm »