Confluence/RequestBuilder.pm

filter: Statementstmt 78.2% 36 / 46 Branchbran 66.6% 8 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 69.2% 9 / 13 Podpod 100% 6 / 6 totaltotal 76.6% 59 / 77 CC 8 SCAR 11.9
CC
8
Cov
76%
_url
6.1
get_content_children
6.0
create_content
2.0
CRAP 3.3
« Confluence/Client.pm ↑ Summary Confluence.pm »
1 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package Footprintless::Plugin::Atlassian::Confluence::RequestBuilder;
5 2 $Footprintless::Plugin::Atlassian::Confluence::RequestBuilder::VERSION = '1.03';
6 # ABSTRACT: A request builder for the Atlassian Confluence REST API
7 # PODNAME: Footprintless::Plugin::Atlassian::Confluence::RequestBuilder
8  
9 2 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use Log::Any;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 my $logger = Log::Any->get_logger();
14  
15 2 ▶sub new {
Subroutine new: called CC=1 SCAR=0.0
Pod documented
16 2 return bless( {}, shift )->_init(@_);
17 }
18  
19 0 ▶sub create_content {
Subroutine create_content: not called CC=1 SCAR=6.9
Pod documented
20 0 my ( $self, $content, %options ) = @_;
21  
22 0 return HTTP::Request->new(
23 'POST',
24 $self->_url( "/rest/api/content", %options ),
25 [ 'Content-Type' => 'application/json' ],
26 encode_json($content)
27 );
28 }
29  
30 0 ▶sub delete_content {
Subroutine delete_content: not called CC=1 SCAR=6.9
Pod documented
31 0 my ( $self, $id ) = @_;
32  
33 0 return HTTP::Request->new( 'DELETE', $self->_url("/rest/api/content/$id") );
34 }
35  
36 5 ▶sub get_content {
Subroutine get_content: called CC=2 SCAR=6.9
Pod documented
37 5 my ( $self, %options ) = @_;
38  
39 5 my $id = delete( $options{id} );
40 5 ▶ return HTTP::Request->new( 'GET',
Branch: 1 branch
BranchTrueFalseTotal
$id ? : 4 1 5
41 $id
42 ? $self->_url( "/rest/api/content/$id", %options )
43 : $self->_url( "/rest/api/content", %options ) );
44 }
45  
46 0 ▶sub get_content_children {
Subroutine get_content_children: not called CC=2 SCAR=17.9
Pod documented
47 0 my ( $self, $id, %options ) = @_;
48  
49 0 my $type = delete( $options{type} );
50 0 ▶ return HTTP::Request->new( 'GET',
Branch: 1 branch
BranchTrueFalseTotal
$type ? : 0 0 0
51 $type
52 ? $self->_url( "/rest/api/content/$id/child/$type", %options )
53 : $self->_url( "/rest/api/content/$id/child", %options ) );
54 }
55  
56 2 ▶sub _init {
Subroutine _init: called CC=1 SCAR=0.0
57 2 my ( $self, $base_url ) = @_;
58  
59 2 $self->{base_url} = $base_url;
60  
61 2 return $self;
62 }
63  
64 0 ▶sub update_content {
Subroutine update_content: not called CC=1 SCAR=6.9
Pod documented
65 0 my ( $self, $id, $content, %options ) = @_;
66  
67 0 return HTTP::Request->new(
68 'PUT',
69 $self->_url( "/rest/api/content/$id", %options ),
70 [ 'Content-Type' => 'application/json' ],
71 encode_json($content)
72 );
73 }
74  
75 5 ▶sub _url {
Subroutine _url: called CC=6 SCAR=18.1
76 5 my ( $self, $path, %query_params ) = @_;
77  
78 5 my $url = "$self->{base_url}$path";
79 5 ▶ if (%query_params) {
Branch: 1 branch
BranchTrueFalseTotal
if (%query_params) 3 2 5
80 3 require URI::Escape;
81 3 my @query_string = ();
82 3 foreach my $key ( sort( keys(%query_params) ) ) {
83 6 ▶ push( @query_string, ( @query_string ? '&' : '?' ) );
Branch: 1 branch
BranchTrueFalseTotal
@query_string ? : 3 3 6
84  
85 push(
86 @query_string,
87 join(
88 '&',
89 6 ▶ map { URI::Escape::uri_escape($key) . '=' . URI::Escape::uri_escape($_) } (
Branch: 1 branch
BranchTrueFalseTotal
ref $query_params{$key} eq 'ARRAY' ? : 0 6 6
90 ref( $query_params{$key} ) eq 'ARRAY'
91 0 ? @{ $query_params{$key} }
92 6 : ( $query_params{$key} )
93 )
94 )
95 );
96 }
97 3 ▶ $url .= ( @query_string ? join( '', @query_string ) : '' );
Branch: 1 branch
BranchTrueFalseTotal
@query_string ? : 3 0 3
98 }
99  
100 5 return $url;
101 }
102  
103 2 1;
104  
105 __END__
« Confluence/Client.pm ↑ Summary Confluence.pm »