Nakamura/ContentUtil.pm

filter: Statementstmt 77.7% 42 / 54 Branchbran 66.6% 12 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 81.8% 9 / 11 Podpod 66.6% 4 / 6 totaltotal 75.2% 67 / 89 CC 10 SCAR 18.2
CC
10
Cov
75%
comment_add_setup
20.0
add_file_metadata_setup
5.0
add_file_perms_setup
3.0
CRAP 6.2
« Nakamura/WorldUtil.pm ↑ Summary Nakamura/UserUtil.pm »
1 #!/usr/bin/perl -w
2  
3 package Sakai::Nakamura::ContentUtil;
4  
5 2 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 require Exporter;
11  
12 2 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 2 our @EXPORT_OK = ();
15  
16 2 our $VERSION = '0.13';
17  
18 #{{{sub add_file_metadata_setup
19  
20 5 ▶sub add_file_metadata_setup {
Subroutine add_file_metadata_setup: called CC=5 SCAR=16.1
Pod documented
21 5 my ( $base_url, $content_path, $content_filename, $content_fileextension ) =
22 @_;
23 5 ▶ if ( !defined $base_url ) { croak 'No base url defined to add against!'; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $base_url) 1 4 5
24 4 ▶ if ( !defined $content_path ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $content_path) 1 3 4
25 1 croak 'No content path to add file meta data to!';
26 }
27 3 ▶ if ( !defined $content_filename ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $content_filename) 1 2 3
28 1 croak 'No content filename provided when attempting to add meta data!';
29 }
30 2 ▶ if ( !defined $content_fileextension ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $content_fileextension) 1 1 2
31 1 croak
32 'No content file extension provided when attempting to add meta data!';
33 }
34 1 my $post_variables =
35 "\$post_variables = ['requests','[{\"url\":\"$content_path\",\"method\":\"POST\",\"parameters\":{\"sakai:pooled-content-file-name\":\"$content_filename\",\"sakai:description\":\"\",\"sakai:permissions\":\"public\",\"sakai:copyright\":\"creativecommons\",\"sakai:allowcomments\":\"true\",\"sakai:showcomments\":\"true\",\"sakai:fileextension\":\"$content_fileextension\",\"_charset_\":\"utf-8\"},\"_charset_\":\"utf-8\"},{\"url\":\"$content_path.save.json\",\"method\":\"POST\",\"_charset_\":\"utf-8\"}]']";
36 1 return "post $base_url/system/batch $post_variables";
37 }
38  
39 #}}}
40  
41 #{{{sub add_file_metadata_eval
42  
43 1 ▶sub add_file_metadata_eval {
Subroutine add_file_metadata_eval: called CC=1 SCAR=0.0
Pod documented
44 1 my ($res) = @_;
45 1 return ( ${$res}->code eq '200' );
46 }
47  
48 #}}}
49  
50 #{{{sub add_file_perms_setup
51  
52 3 ▶sub add_file_perms_setup {
Subroutine add_file_perms_setup: called CC=3 SCAR=11.0
Pod documented
53 3 my ( $base_url, $content_path ) = @_;
54 3 ▶ if ( !defined $base_url ) { croak 'No base url defined to add against!'; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $base_url) 1 2 3
55 2 ▶ if ( !defined $content_path ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $content_path) 1 1 2
56 1 croak 'No content path to add file perms to!';
57 }
58 1 my $post_variables =
59 "\$post_variables = ['requests','[{\"url\":\"$content_path.members.html\",\"method\":\"POST\",\"parameters\":{\":viewer\":[\"everyone\",\"anonymous\"]}},{\"url\":\"$content_path.modifyAce.html\",\"method\":\"POST\",\"parameters\":{\"principalId\":[\"everyone\"],\"privilege\@jcr:read\":\"granted\"}},{\"url\":\"$content_path.modifyAce.html\",\"method\":\"POST\",\"parameters\":{\"principalId\":[\"anonymous\"],\"privilege\@jcr:read\":\"granted\"}}]']";
60 1 return "post $base_url/system/batch $post_variables";
61 }
62  
63 #}}}
64  
65 #{{{sub add_file_perms_eval
66  
67 1 ▶sub add_file_perms_eval {
Subroutine add_file_perms_eval: called CC=1 SCAR=0.0
Pod documented
68 1 my ($res) = @_;
69 1 return ( ${$res}->code eq '200' );
70 }
71  
72 #}}}
73  
74 #{{{sub comment_add_setup
75  
76 0 ▶sub comment_add_setup {
Subroutine comment_add_setup: not called CC=4 SCAR=30.0
Pod undocumented
77 0 my ( $base_url, $content_path, $comment ) = @_;
78 0 ▶ if ( !defined $base_url ) { croak 'No base url defined to add against!'; }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $base_url) 0 0 0
79 0 ▶ if ( !defined $content_path ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $content_path) 0 0 0
80 0 croak 'No content path to add comments to!';
81 }
82 0 ▶ if ( !defined $comment ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $comment) 0 0 0
83 0 croak 'No comment provided to add!';
84 }
85 0 my $post_variables = "\$post_variables = ['comment','$comment']";
86 0 return "post $base_url/$content_path.comments $post_variables";
87 }
88  
89 #}}}
90  
91 #{{{sub comment_add_eval
92  
93 0 ▶sub comment_add_eval {
Subroutine comment_add_eval: not called CC=1 SCAR=6.9
Pod undocumented
94 0 my ($res) = @_;
95 0 return ( ${$res}->code eq '201' );
96 }
97  
98 #}}}
99  
100 2 1;
101  
102 __END__
« Nakamura/WorldUtil.pm ↑ Summary Nakamura/UserUtil.pm »