| 1 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | package Footprintless::Plugin::Atlassian::Confluence::Client; | ||||||||||||||||||||||||||||
| 5 | 1 | $Footprintless::Plugin::Atlassian::Confluence::Client::VERSION = '1.03'; | |||||||||||||||||||||||||||
| 6 | # ABSTRACT: A REST client for Atlassian Confluence | ||||||||||||||||||||||||||||
| 7 | # PODNAME: Footprintless::Plugin::Atlassian::Confluence::Client | ||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use parent qw(Footprintless::MixableBase); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Footprintless::Mixins qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | _sub_entity | ||||||||||||||||||||||||||||
| 13 | 1 | ); | |||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Footprintless::Util qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | dynamic_module_new | ||||||||||||||||||||||||||||
| 16 | 1 | ); | |||||||||||||||||||||||||||
| 17 | 1 | ▶ | use Log::Any; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 1 | my $logger = Log::Any->get_logger(); | |||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 2 | ▶ | sub _init { | ||||||||||||||||||||||||||
|
Subroutine
_init: called CC=4 SCAR=14.2
| |||||||||||||||||||||||||||||
| 22 | 2 | my ( $self, %options ) = @_; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 2 | $self->{username} = $self->_sub_entity( 'automation.username', 1 ); | |||||||||||||||||||||||||||
| 25 | 2 | $self->{password} = $self->_sub_entity( 'automation.password', 1 ); | |||||||||||||||||||||||||||
| 26 | 2 | ▶ | $self->{agent} = $options{agent} || $self->{factory}->agent(); | ||||||||||||||||||||||||||
|
Condition33%1/3
$options{'agent'} || $self->{'factory'}->agent
MC/DC0%0/2
$options{'agent'} || $self->{'factory'}->agent
$options{'agent'}
$self->{'factory'}->agent
Truth table33%1/3
A || B
A= $options{'agent'}B= $self->{'factory'}->agent
| |||||||||||||||||||||||||||||
| 27 | $self->{request_builder} = dynamic_module_new( | ||||||||||||||||||||||||||||
| 28 | ( $options{request_builder_module} | ||||||||||||||||||||||||||||
| 29 | 2 | ▶ | || 'Footprintless::Plugin::Atlassian::Confluence::RequestBuilder' | ||||||||||||||||||||||||||
|
Condition100%2/2
$options{'request_builder_module'} || 'Footprintless::Plugin::Atlassian::Confluence::RequestBuilder'
MC/DC100%1/1
$options{'request_builder_module'} || 'Footprintless::Plugin::Atlassian::Confluence::RequestBuilder'
$options{'request_builder_module'}
Truth table100%2/2
A
A= $options{'request_builder_module'}
| |||||||||||||||||||||||||||||
| 30 | ), | ||||||||||||||||||||||||||||
| 31 | $self->_web_url() | ||||||||||||||||||||||||||||
| 32 | ); | ||||||||||||||||||||||||||||
| 33 | $self->{response_parser} = dynamic_module_new( | ||||||||||||||||||||||||||||
| 34 | ( $options{response_parser_module} | ||||||||||||||||||||||||||||
| 35 | 2 | ▶ | || 'Footprintless::Plugin::Atlassian::Confluence::ResponseParser' | ||||||||||||||||||||||||||
|
Condition50%1/2
$options{'response_parser_module'} || 'Footprintless::Plugin::Atlassian::Confluence::ResponseParser'
MC/DC0%0/1
$options{'response_parser_module'} || 'Footprintless::Plugin::Atlassian::Confluence::ResponseParser'
$options{'response_parser_module'}
Truth table50%1/2
A
A= $options{'response_parser_module'}
| |||||||||||||||||||||||||||||
| 36 | ) | ||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 2 | return $self; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 2 | ▶ | sub request { | ||||||||||||||||||||||||||
|
Subroutine
request: called CC=9 SCAR=29.5
Pod
documented
| |||||||||||||||||||||||||||||
| 43 | 2 | my ( $self, $endpoint, $args, %response_options ) = @_; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 2 | my $response; | |||||||||||||||||||||||||||
| 46 | 2 | eval { | |||||||||||||||||||||||||||
| 47 | 2 | $logger->debugf( 'requesting %s', $endpoint ); | |||||||||||||||||||||||||||
| 48 | 2 | ▶ | my $http_request = $self->{request_builder}->$endpoint( ( $args ? @$args : () ) ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | 2 | $http_request->authorization_basic( $self->{username}, $self->{password} ); | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 2 | ▶ | if ( $logger->is_trace() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | 0 | $logger->trace( | |||||||||||||||||||||||||||
| 53 | join( '', | ||||||||||||||||||||||||||||
| 54 | "----------------------BEGIN REQUEST--------------------\n", | ||||||||||||||||||||||||||||
| 55 | $http_request->dump( maxlength => 500 ), | ||||||||||||||||||||||||||||
| 56 | "\n---------------------- END REQUEST --------------------\n" ) | ||||||||||||||||||||||||||||
| 57 | ); | ||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 2 | my @content = (); | |||||||||||||||||||||||||||
| 61 | 2 | ▶ | if ( $response_options{content_file} ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 62 | 0 | $logger->tracef( 'writing response to %s', $response_options{content_file} ); | |||||||||||||||||||||||||||
| 63 | 0 | push( @content, $response_options{content_file} ); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | elsif ( $response_options{content_cb} ) { | ||||||||||||||||||||||||||||
| 66 | 0 | $logger->trace('writing response to callback'); | |||||||||||||||||||||||||||
| 67 | 0 | push( @content, $response_options{content_cb}, $response_options{read_size_hint} ); | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 2 | my $http_response = $self->{agent}->request( $http_request, @content ); | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 2 | ▶ | if ( $logger->is_trace() ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 73 | 0 | $logger->trace( | |||||||||||||||||||||||||||
| 74 | join( '', | ||||||||||||||||||||||||||||
| 75 | "----------------------BEGIN RESPONSE--------------------\n", | ||||||||||||||||||||||||||||
| 76 | $http_response->dump( maxlength => 500 ), | ||||||||||||||||||||||||||||
| 77 | "\n---------------------- END RESPONSE --------------------\n" ) | ||||||||||||||||||||||||||||
| 78 | ); | ||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 2 | $response = $self->{response_parser}->$endpoint( $http_response, %response_options ); | |||||||||||||||||||||||||||
| 82 | }; | ||||||||||||||||||||||||||||
| 83 | 2 | ▶ | if ($@) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | if ( ref($@) eq 'HASH' && $@->{code} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $@ eq "HASH" and $@->{"code"}
MC/DC0%0/2
ref $@ eq "HASH" and $@->{"code"}
ref $@ eq "HASH"
$@->{"code"}
Truth table0%0/3
A and B
A= ref $@ eq "HASH"B= $@->{"code"}
| |||||||||||||||||||||||||||||
| 85 | 0 | $response = $@; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | else { | ||||||||||||||||||||||||||||
| 88 | 0 | $response = { | |||||||||||||||||||||||||||
| 89 | code => 500, | ||||||||||||||||||||||||||||
| 90 | content => {}, | ||||||||||||||||||||||||||||
| 91 | message => $@, | ||||||||||||||||||||||||||||
| 92 | success => 0, | ||||||||||||||||||||||||||||
| 93 | }; | ||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | 2 | return $response; | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub request_all { | ||||||||||||||||||||||||||
|
Subroutine
request_all: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||
| 100 | 0 | my ( $self, $endpoint, $args, @response_options ) = @_; | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | my $response = $self->request( | |||||||||||||||||||||||||||
| 103 | $endpoint, | ||||||||||||||||||||||||||||
| 104 | [ @$args, | ||||||||||||||||||||||||||||
| 105 | limit => 100, | ||||||||||||||||||||||||||||
| 106 | start => 0 | ||||||||||||||||||||||||||||
| 107 | ], | ||||||||||||||||||||||||||||
| 108 | @response_options | ||||||||||||||||||||||||||||
| 109 | ); | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 0 | my $next = $response; | |||||||||||||||||||||||||||
| 112 | 0 | ▶ | while ( $next->{success} && $next->{content}{_links}{next} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$next->{"success"} and $next->{"content"}{"_links"}{"next"}
MC/DC0%0/2
$next->{"success"} and $next->{"content"}{"_links"}{"next"}
$next->{"success"}
$next->{"content"}{"_links"}{"next"}
Truth table0%0/3
A and B
A= $next->{"success"}B= $next->{"content"}{"_links"}{"next"}
| |||||||||||||||||||||||||||||
| 113 | 0 | my $limit = $response->{content}{limit}; | |||||||||||||||||||||||||||
| 114 | $next = $self->request( | ||||||||||||||||||||||||||||
| 115 | $endpoint, | ||||||||||||||||||||||||||||
| 116 | [ @$args, | ||||||||||||||||||||||||||||
| 117 | limit => $limit, | ||||||||||||||||||||||||||||
| 118 | 0 | start => $next->{content}{start} + $limit, | |||||||||||||||||||||||||||
| 119 | ], | ||||||||||||||||||||||||||||
| 120 | @response_options | ||||||||||||||||||||||||||||
| 121 | ); | ||||||||||||||||||||||||||||
| 122 | 0 | push( @{ $response->{content}{results} }, @{ $next->{content}{results} } ); | |||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 0 | delete( $response->{content}{_links}{next} ); | |||||||||||||||||||||||||||
| 126 | 0 | $response->{content}{limit} = scalar( @{ $response->{content}{results} } ); | |||||||||||||||||||||||||||
| 127 | 0 | $response->{content}{size} = $response->{content}{limit}; | |||||||||||||||||||||||||||
| 128 | 0 | $response->{content}{start} = 0; | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | return $response; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 2 | ▶ | sub _web_url { | ||||||||||||||||||||||||||
|
Subroutine
_web_url: called CC=4 SCAR=15.2
| |||||||||||||||||||||||||||||
| 134 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 135 | 2 | my $web = $self->_sub_entity( 'web', 1 ); | |||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | return | ||||||||||||||||||||||||||||
| 138 | ( $web->{https} ? 'https://' : 'http://' ) | ||||||||||||||||||||||||||||
| 139 | . $web->{hostname} | ||||||||||||||||||||||||||||
| 140 | . ( $web->{port} ? ":$web->{port}" : '' ) | ||||||||||||||||||||||||||||
| 141 | 2 | ▶ | . ( $web->{context_path} || '' ); | ||||||||||||||||||||||||||
|
Branch: 2 branches
Condition50%1/2
$web->{'context_path'} || ''
MC/DC0%0/1
$web->{'context_path'} || ''
$web->{'context_path'}
Truth table50%1/2
A
A= $web->{'context_path'}
| |||||||||||||||||||||||||||||
| 142 | } | ||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||
| 144 | 1 | 1; | |||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||
| 146 | __END__ | ||||||||||||||||||||||||||||