Devel/IPerl/Display/Role/MIMESource.pm

filter: Statementstmt 83.3% 40 / 48 Branchbran 42.8% 6 / 14 Conditioncond 66.6% 2 / 3 MC/DCmcdc 50.0% 1 / 2 Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 76.9% 60 / 78 CC 9 SCAR 16.7
CC
9
Cov
74%
_build__data
13.0
_html_uri
5.4
BEGIN
1.0
CRAP 5.3
« Devel/IPerl/DisplayableHandler.pm ↑ Summary Devel/IPerl/Kernel.pm »
1 package Devel::IPerl::Display::Role::MIMESource;
2 2 $Devel::IPerl::Display::Role::MIMESource::VERSION = '0.012';
3 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use autodie;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use MooX::Types::MooseLike::Base qw(Bool);
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 with qw(Devel::IPerl::Display::Role::Source Devel::IPerl::Display::Role::MIMEType);
14  
15 4 ▶has use_data_uri => ( is => 'rw', isa => Bool, default => sub { 1 } );
Subroutine __ANON__: called CC=1 SCAR=0.0
16  
17 2 has _data => ( is => 'lazy', clearer => 1, builder => 1 );
18  
19 5 ▶sub _build__data {
Subroutine _build__data: called CC=5 SCAR=25.7
20 5 my ($self) = @_;
21 5 ▶ if( $self->bytestream ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->bytestream) { } 0 5 5
elsif ($self->filename) { } 5 0 5
elsif ($self->uri) { } 0 0 0
22 0 return $self->bytestream;
23 } elsif( $self->filename ) {
24 5 my $data = file( $self->filename )->slurp( iomode => '<:raw' );
25 5 return $data;
26 } elsif( $self->uri ) {
27 0 my $ua = LWP::UserAgent->new();
28 0 my $response = $ua->get( $self->uri );
29 0 ▶ die "Could not retrieve data" unless $response->is_success;
Branch: 1 branch
BranchTrueFalseTotal
unless $response->is_success 0 0 0
30 0 my $data = $response->decoded_content;
31 0 return $data;
32 }
33 0 die "No data to build display"; # TODO create exception class
34 }
35  
36 5 ▶sub _html_uri {
Subroutine _html_uri: called CC=5 SCAR=16.8
37 5 my ($self) = @_;
38 5 ▶ if( $self->bytestream || $self->use_data_uri ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->bytestream or $self->use_data_uri) { } 4 1 5
elsif ($self->uri) { } 0 1 1
elsif ($self->filename) { } 1 0 1
Condition66%2/3
$self->bytestream or $self->use_data_uri
l!l&&r!l&&!r
041
MC/DC50%1/2
$self->bytestream or $self->use_data_uri
$self->bytestream $self->use_data_uri
Truth table66%2/3
A or B
A= $self->bytestreamB= $self->use_data_uri
ABresult
1X1
011
000
39 4 return "data:@{[ $self->mimetype ]};base64,@{[ encode_base64($self->_data) ]}";
40 } elsif( $self->uri ) {
41 0 return $self->uri;
42 } elsif( $self->filename ) {
43 1 return file($self->filename)->absolute; # TODO should this be a URI? Use Path::Class:URI for that.
44 }
45 }
46  
47 2 1;
48  
49 __END__
« Devel/IPerl/DisplayableHandler.pm ↑ Summary Devel/IPerl/Kernel.pm »