V3/_Content.pm

filter: Statementstmt 29.1% 23 / 79 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 16 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 53.8% 7 / 13 Podpod 75.0% 3 / 4 totaltotal 22.9% 33 / 144 CC 20 SCAR 41.1
CC
20
Cov
20%
upload
110.0
BUILDARGS
90.0
_freeze
6.0
CRAP 60.8
« V3/Session.pm ↑ Summary V3/Recording.pm »
1 package Bb::Collaborate::V3::_Content;
2 7 ▶use warnings; use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 7 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 7 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use Try::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use MIME::Base64;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 7 ▶use File::Basename;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 7 extends 'Bb::Collaborate::V3';
12  
13 =head1 NAME
14  
15 Bb::Collaborate::V3::_Content - Base class for Presentation and Mulitmedia content
16  
17 =cut
18  
19 0 ▶sub BUILDARGS {
Subroutine BUILDARGS: not called CC=9 SCAR=45.0
Pod documented
20 0 my $class = shift;
21 0 my $spec = shift;
22  
23 0 my %args;
24  
25 0 ▶ if (defined $spec && ! ref($spec) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $spec and not ref $spec) { } 0 0 0
elsif (Elive::Util::_reftype($spec) eq 'HASH') { } 0 0 0
Condition0%0/3
defined $spec and not ref $spec
!ll&&!rl&&r
000
MC/DC0%0/2
defined $spec and not ref $spec
defined $spec not ref $spec
Truth table0%0/3
A and not(B)
A= defined $specB= not ref $spec
ABresult
0X0
100
111
26 #
27 # Assume a single string arguments represents the local path of a file
28 # to be uploaded.
29 #
30 0 my $content_path = $spec;
31  
32 0 ▶ open ( my $fh, '<', $content_path)
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $content_path or die "unable to open content file $content_path" 0 0 0
33 or die "unable to open content file $content_path";
34  
35 0 binmode $fh;
36 0 my $content = do {local $/; <$fh>};
37  
38 0 close $fh;
39  
40 0 ▶ die "content file is empty: $content_path"
Branch: 1 branch
BranchTrueFalseTotal
unless length $content 0 0 0
41 unless length $content;
42  
43 0 my $filename = File::Basename::basename( $content_path );
44 0 ▶ croak "unable to determine a basename for content path: $content_path"
Branch: 1 branch
BranchTrueFalseTotal
unless length $filename 0 0 0
45 unless length $filename;
46  
47 0 %args = (
48 filename => $content_path,
49 content => $content,
50 );
51 }
52 elsif (Elive::Util::_reftype($spec) eq 'HASH') {
53 0 %args = %$spec;
54 }
55 else {
56 0 croak 'usage: '.$class.'->new( filepath | {name => $filename, content => $binary_data, ...} )';
57 }
58  
59 0 ▶ if ($args{content}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($args{"content"}) 0 0 0
60 0 ▶ $args{size} ||= length( $args{content} );
Condition0%0/3
$args{"size"} ||= length $args{"content"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$args{"size"} ||= length $args{"content"}
$args{"size"} length $args{"content"}
Truth table0%0/3
A ||= B
A= $args{"size"}B= length $args{"content"}
ABresult
1X1
011
000
61 }
62  
63 0 return \%args;
64 }
65  
66 0 ▶sub _freeze {
Subroutine _freeze: not called CC=2 SCAR=17.9
67 0 my $class = shift;
68 0 my %db_data = %{ shift() };
69  
70 0 my $content = delete $db_data{content};
71 0 my $db_data = $class->SUPER::_freeze( \%db_data );
72  
73 0 ▶ if (defined $content) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $content) 0 0 0
74 #
75 # (a bit of layer bleed here...). Do we need a separate data type
76 # for base 64 encoded data?
77 #
78 0 require SOAP::Lite;
79 0 $db_data->{content} = SOAP::Data->type('xs:base64Binary' => MIME::Base64::encode_base64($content,'') );
80 }
81  
82 0 return $db_data;
83 }
84  
85 0 ▶sub upload {
Subroutine upload: not called CC=10 SCAR=47.0
Pod undocumented
86 0 my ($class, $spec, %opt) = @_;
87  
88 my $command = (delete($opt{command})
89 0 ▶ || 'UploadRepository' . $class->entity_name);
Condition0%0/2
delete $opt{'command'} || 'UploadRepository' . $class->entity_name
l!l
00
MC/DC0%0/1
delete $opt{'command'} || 'UploadRepository' . $class->entity_name
delete $opt{'command'}
Truth table0%0/2
A
A= delete $opt{'command'}
Aresult
11
00
90  
91 0 my %upload_data = %{ $class->BUILDARGS( $spec ) };
92  
93 0 ▶ my $connection = delete $opt{connection} || $class->connection
Branch: 1 branch
BranchTrueFalseTotal
my $connection = delete $opt{"connection"} || $class->connection or die "not connected" 0 0 0
Condition0%0/3
delete $opt{'connection'} || $class->connection
l!l&&r!l&&!r
000
MC/DC0%0/2
delete $opt{'connection'} || $class->connection
delete $opt{'connection'} $class->connection
Truth table0%0/3
A || B
A= delete $opt{'connection'}B= $class->connection
ABresult
1X1
011
000
94 or die "not connected";
95  
96 0 ▶ $upload_data{creatorId} ||= $connection->user;
Condition0%0/3
$upload_data{"creatorId"} ||= $connection->user
l!l&&r!l&&!r
000
MC/DC0%0/2
$upload_data{"creatorId"} ||= $connection->user
$upload_data{"creatorId"} $connection->user
Truth table0%0/3
A ||= B
A= $upload_data{"creatorId"}B= $connection->user
ABresult
1X1
011
000
97  
98 0 ▶ my %params = %{delete $opt{param} || {}};
Condition0%0/2
delete $opt{'param'} || {}
l!l
00
MC/DC0%0/1
delete $opt{'param'} || {}
delete $opt{'param'}
Truth table0%0/2
A
A= delete $opt{'param'}
Aresult
11
00
99  
100 0 my %data_params = %{ $class->_freeze({%upload_data, %params}) };
101  
102 #
103 # work around SAS bug. upload commands apear to be order sensitive
104 #
105 0 my @args;
106 0 for (qw<creatorId filename description content size>) {
107 push @args, $_ => delete $data_params{$_}
108 0 ▶ if exists $data_params{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $data_params{$_} 0 0 0
109 }
110  
111 # mop up
112 push @args, $_ => $data_params{$_}
113 0 for keys %data_params;
114  
115 0 $connection->check_command($command => 'c');
116 0 my $som = $connection->call($command, @args);
117 0 my @rows = $class->_readback($som, \%upload_data, $connection, %opt);
118  
119 0 my @objs = (map {$class->construct( $_, connection => $connection )}
120 @rows);
121 #
122 # possibly return a list of recurring meetings.
123 #
124 0 ▶ return wantarray? @objs : $objs[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
125 }
126  
127 0 ▶sub list {
Subroutine list: not called CC=1 SCAR=6.9
Pod documented
128 0 my ($self, @args) = @_;
129  
130 return $self->SUPER::list(
131 @args,
132 0 ▶ command => sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
133 0 my ($_crud, $params) = @_;
134 0 my $ent = $self->entity_name;
135  
136 0 ▶ return exists $params->{sessionId} ? "ListSession${ent}": "ListRepository${ent}"
Branch: 1 branch
BranchTrueFalseTotal
exists $params->{'sessionId'} ? : 0 0 0
137 },
138 0 );
139 }
140  
141 0 ▶sub delete {
Subroutine delete: not called CC=1 SCAR=6.9
Pod documented
142 0 my ($self, %opt) = @_;
143  
144 0 return $self->SUPER::delete( %opt, command => 'RemoveRepository'.$self->entity_name);
145 }
146  
147 7 1;
« V3/Session.pm ↑ Summary V3/Recording.pm »