Controller/SimpleCAS/MimeUriResolver.pm

filter: Statementstmt 57.5% 19 / 33 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 62.5% 5 / 8 Podpod 100% 1 / 1 totaltotal 56.8% 25 / 44 CC 2 SCAR 8.5
CC
2
Cov
54%
get_resource
6.0
__ANON__
2.0
__ANON__
2.0
CRAP 2.3
« Controller/SimpleCAS/Store/File.pm ↑ Summary Plugin/SimpleCAS.pm »
1 package Catalyst::Controller::SimpleCAS::MimeUriResolver;
2 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 ▶use Email::MIME::CreateHTML::Resolver::LWP;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 has 'Cas' => (
12 is => 'ro',
13 isa => 'Catalyst::Controller::SimpleCAS',
14 required => 1
15 );
16  
17 has 'Resolver' => (
18 is => 'ro',
19 isa => 'Object',
20 lazy => 1,
21 0 ▶ default => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
22 0 my $self = shift;
23 0 return Email::MIME::CreateHTML::Resolver::LWP->new({ base => $self->base });
24 }
25 1 );
26  
27 1 has 'base' => (
28 is => 'ro',
29 isa => 'Str',
30 required => 1
31 );
32  
33  
34 0 ▶sub get_resource {
Subroutine get_resource: not called CC=2 SCAR=17.9
Pod documented
35 0 my $self = shift;
36 0 my ($uri) = @_;
37
38 0 my ($content,$filename,$mimetype,$xfer_encoding);
39
40 0 my $Content = $self->Cas->uri_find_Content($uri);
41 0 ▶ if($Content) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Content) { } 0 0 0
42 0 $content = $Content->content;
43 0 $filename = $Content->MIME->filename(1);
44 0 $mimetype = $Content->MIME->content_type;
45 0 $xfer_encoding = $Content->MIME->header('Content-Transfer-Encoding');
46 }
47 else {
48 0 ▶ try {
Subroutine __ANON__: not called CC=1 SCAR=6.9
49 # TODO:
50 # This will throw an exception if the url is relative:
51 # "Could not fetch <url> : 400 URL must be absolute"
52 # Relative urls probably indicate it is a resource of the
53 # local application; we should handle this case by setting
54 # up a virtual/internal request. In the mean time, we
55 # are wrapping in a try block to avoid dumping the whole
56 # request, so at least something can be returned, even if
57 # it is missing some inline images, etc
58 0 ($content,$filename,$mimetype,$xfer_encoding) = $self->Resolver->get_resource(@_);
59 }
60 0 }
61
62 0 return ($content,$filename,$mimetype,$xfer_encoding);
63 }
64  
65  
66 1 1;
67  
68 __END__
« Controller/SimpleCAS/Store/File.pm ↑ Summary Plugin/SimpleCAS.pm »