Silki/Role/Schema/URIMaker.pm untested

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 68 CC 6 SCAR 18.3
CC
6
Cov
0%
uri
12.0
_host_params_for_uri
12.0
_make_uri
6.0
CRAP 6.2
1 package Silki::Role::Schema::URIMaker;
2 {
3 $Silki::Role::Schema::URIMaker::VERSION = '0.29';
4 }
5  
6 use strict;
7 use warnings;
8 use namespace::autoclean;
9  
10 use MooseX::Params::Validate qw( validate );
11 use Silki::Types qw( Bool HashRef Int Str );
12 use Silki::Util qw( string_is_empty );
13 use Silki::URI qw( dynamic_uri );
14  
15 use Moose::Role;
16  
17 #requires_attr_or_method (??) 'domain';
18  
19 requires '_base_uri_path';
20  
21 sub uri {
22 # MX::P::V doesn't handle class methods
23 my $self = shift;
24  
25 my %p = validate(
26 \@_,
27 view => { isa => Str, optional => 1 },
28 fragment => { isa => Str, optional => 1 },
29 query => { isa => HashRef, default => {} },
30 host => { isa => Str, optional => 1 },
31 port => { isa => Int, optional => 1 },
32 with_host => { isa => Bool, default => 0 },
33 );
34  
35 my $path = $self->_base_uri_path();
36 unless ( string_is_empty( $p{view} ) ) {
37 $path .= q{/} unless $path =~ m{/$};
38 $path .= $p{view};
39 }
40  
41 delete $p{view};
42  
43 $self->_make_uri(
44 path => $path,
45 %p,
46 );
47 }
48  
49 sub _make_uri {
50 my $self = shift;
51 my %p = @_;
52  
53 delete $p{fragment}
54 if string_is_empty( $p{fragment} );
55  
56 return dynamic_uri(
57 $self->_host_params_for_uri( delete $p{with_host} ),
58 %p,
59 );
60 }
61  
62 sub _host_params_for_uri {
63 my $self = shift;
64  
65 return unless $_[0];
66  
67 return (
68 %{ $self->domain()->uri_params() },
69 (
70 $ENV{SERVER_PORT}
71 ? ( port => $ENV{SERVER_PORT} )
72 : ()
73 )
74 );
75 }
76  
77 1;
78  
79 # ABSTRACT: Adds an $object->uri() method
80  
81 __END__