| 1 | package Webservice::Overleaf::API; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use v5.10; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 9 | our $VERSION = '0.06'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | # General-purpose Overleaf tooling, also informed by practical Science Perl | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | # Journal author/editor work. The author is a Science Perl Committee member | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | # and a Co-Editor of the Journal; see the POD for context and links. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 9 | ▶ | use Carp qw/croak/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 9 | ▶ | use Dispatch::Fu qw/dispatch on xdefault xshift_and_deref/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 9 | ▶ | use HTML::Entities qw/decode_entities/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 9 | ▶ | use HTTP::Tiny; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 9 | ▶ | use JSON::PP qw/decode_json encode_json/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 9 | ▶ | use MIME::Base64 qw/encode_base64/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 9 | ▶ | use URI::Escape qw/uri_escape_utf8/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 9 | ▶ | use Util::H2O::More qw/baptise d2o h2o/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 9 | ▶ | use constant { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 9 | DEFAULT_BASE_URL => 'https://www.overleaf.com', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | DEFAULT_GIT_BASE_URL => 'https://git.overleaf.com', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 9 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 15 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=9 SCAR=22.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 15 | my $pkg = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 15 | my %opts = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | my $base_url = defined $opts{base_url} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | ? $opts{base_url} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 15 | ▶ | : DEFAULT_BASE_URL; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 15 | $base_url =~ s{/+$}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 15 | my $git_base_url; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 15 | ▶ | if (defined $opts{git_base_url}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | $git_base_url = $opts{git_base_url}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | elsif ($base_url eq DEFAULT_BASE_URL) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 14 | $git_base_url = DEFAULT_GIT_BASE_URL; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # Overleaf Server Pro commonly exposes Git below /git. A deployment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # with a different Git bridge location should pass git_base_url. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 1 | $git_base_url = $base_url . '/git'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 15 | $git_base_url =~ s{/+$}{}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | # Keep HTTP construction lazy. HTTP::Tiny reads proxy-related | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | # environment variables in new(), which should not make URL builders or | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | # Git-only use fail before an HTTP request is ever attempted. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | my $self = baptise { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | ua => $opts{ua}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | timeout => defined $opts{timeout} ? $opts{timeout} : 30, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | base_url => $base_url, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | git_base_url => $git_base_url, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | session => defined $opts{session} ? $opts{session} : $ENV{OVERLEAF_SESSION}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | cookie_name => $opts{cookie_name} || 'overleaf_session2', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | csrf => $opts{csrf}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | experimental => $opts{experimental} ? 1 : 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 15 | ▶ | git_runner => $opts{git_runner} || \&_default_git_runner, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition75%3/4
$opts{'cookie_name'} || 'overleaf_session2'
$opts{'git_runner'} || \&Webservice::Overleaf::API::_default_git_runner
MC/DC0%0/1
$opts{'cookie_name'} || 'overleaf_session2'
$opts{'cookie_name'}
MC/DC100%1/1
$opts{'git_runner'} || \&Webservice::Overleaf::API::_default_git_runner
$opts{'git_runner'}
Truth table50%1/2
A
A= $opts{'cookie_name'}
Truth table100%2/2
A
A= $opts{'git_runner'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | last_response => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | }, $pkg; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 15 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 6 | ▶ | sub project_url { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
project_url: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 6 | my ($self, $project_id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 6 | $project_id = _project_id($project_id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 6 | return $self->base_url . '/project/' . $project_id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 7 | ▶ | sub git_url { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
git_url: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 7 | my ($self, $project_id) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 7 | $project_id = _project_id($project_id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 6 | my $base = $self->git_base_url; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # Overleaf Cloud documents the public Git username as "git". Keep the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # token out of the URL, but include that non-secret username so ordinary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | # Git does not guess an account email address when it needs credentials. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 6 | $base =~ s{\Ahttps://git\.overleaf\.com(?=/|\z)}{https://git\@git.overleaf.com}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 6 | return $base . '/' . $project_id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 8 | ▶ | sub open_uri { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
open_uri: called CC=20 SCAR=33.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 8 | my %opts = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 8 | my $uris = delete $opts{uris}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 8 | ▶ | $uris = [ delete $opts{uri} ] if !defined $uris && exists $opts{uri}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $uris and exists $opts{"uri"}
MC/DC50%1/2
not defined $uris and exists $opts{"uri"}
not defined $uris
exists $opts{"uri"}
Truth table66%2/3
not(A) and B
A= not defined $urisB= exists $opts{"uri"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 8 | ▶ | $uris = [$uris] if defined $uris && ref($uris) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $uris and ref $uris ne "ARRAY"
MC/DC0%0/2
defined $uris and ref $uris ne "ARRAY"
defined $uris
ref $uris ne "ARRAY"
Truth table33%1/3
A and B
A= defined $urisB= ref $uris ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | croak 'open_uri requires uri => $uri or uris => \\@uris' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 8 | ▶ | if !$uris || !@$uris || grep { !defined($_) || $_ eq q{} } @$uris; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
not $uris && @$uris or grep {not defined $_ or $_ eq "";} @$uris
$uris && @$uris
!defined($_) || $_ eq ''
MC/DC0%0/3
not $uris && @$uris or grep {not defined $_ or $_ eq "";} @$uris
$uris
@$uris
grep {not defined $_ or $_ eq "";} @$uris
MC/DC0%0/2
!defined($_) || $_ eq ''
!defined($_)
$_ eq ''
Truth table25%1/4
not(A && B) or C
A= $urisB= @$urisC= grep {not defined $_ or $_ eq "";} @$uris
Truth table33%1/3
not(A) || B
A= !defined($_)B= $_ eq ''
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 8 | my $names = delete $opts{names}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 8 | ▶ | $names = [ delete $opts{name} ] if !defined $names && exists $opts{name}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $names and exists $opts{"name"}
MC/DC0%0/2
not defined $names and exists $opts{"name"}
not defined $names
exists $opts{"name"}
Truth table66%2/3
not(A) and B
A= not defined $namesB= exists $opts{"name"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 8 | ▶ | $names = [$names] if defined $names && ref($names) ne 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $names and ref $names ne "ARRAY"
MC/DC0%0/2
defined $names and ref $names ne "ARRAY"
defined $names
ref $names ne "ARRAY"
Truth table66%2/3
A and B
A= defined $namesB= ref $names ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 8 | ▶ | croak 'names must contain one entry for each URI' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$names and @$names != @$uris
MC/DC100%2/2
$names and @$names != @$uris
$names
@$names != @$uris
Truth table100%3/3
A and B
A= $namesB= @$names != @$uris
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | if $names && @$names != @$uris; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 7 | my @pairs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 7 | ▶ | if (@$uris == 1 && !$names) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@$uris == 1 and not $names
MC/DC50%1/2
@$uris == 1 and not $names
@$uris == 1
not $names
Truth table66%2/3
A and not(B)
A= @$uris == 1B= not $names
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 6 | push @pairs, [ snip_uri => $uris->[0] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1 | for my $i (0 .. $#$uris) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 2 | push @pairs, [ 'snip_uri[]' => $uris->[$i] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 2 | ▶ | push @pairs, [ 'snip_name[]' => $names->[$i] ] if $names; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 7 | _append_open_features(\@pairs, \%opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 6 | ▶ | croak 'unsupported open_uri option(s): ' . join(', ', sort keys %opts) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | if keys %opts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 6 | return $self->base_url . '/docs?' . _query_string(@pairs); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 2 | ▶ | sub open_data { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
open_data: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 2 | my ($self, $content, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 2 | ▶ | croak 'open_data requires content' if !defined $content; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 2 | ▶ | my $mime = delete($opts{mime}) || 'application/x-tex'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
delete $opts{'mime'} || 'application/x-tex'
MC/DC100%1/1
delete $opts{'mime'} || 'application/x-tex'
delete $opts{'mime'}
Truth table100%2/2
A
A= delete $opts{'mime'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 2 | my $uri = 'data:' . $mime . ';base64,' . encode_base64($content, q{}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 2 | return $self->open_uri(uri => $uri, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 1 | ▶ | sub open_snippet_form { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
open_snippet_form: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 1 | my ($self, $snippet, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | ▶ | croak 'open_snippet_form requires a snippet' if !defined $snippet; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | my %fields = (snip => $snippet); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | _append_open_features_hash(\%fields, \%opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | ▶ | croak 'unsupported open_snippet_form option(s): ' . join(', ', sort keys %opts) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | if keys %opts; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | return d2o { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | action => $self->base_url . '/docs', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | method => 'POST', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | fields => \%fields, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | ▶ | sub git_clone { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
git_clone: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 1 | my ($self, $project_id, $directory) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | ▶ | croak 'git_clone requires a destination directory' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $directory or $directory eq ""
MC/DC0%0/2
not defined $directory or $directory eq ""
not defined $directory
$directory eq ""
Truth table33%1/3
not(A) or B
A= not defined $directoryB= $directory eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | if !defined($directory) || $directory eq q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | return $self->_run_git('git', 'clone', $self->git_url($project_id), $directory); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 2 | ▶ | sub git_pull { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
git_pull: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 2 | my ($self, $directory) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 2 | ▶ | croak 'git_pull requires a repository directory' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $directory or $directory eq ""
MC/DC0%0/2
not defined $directory or $directory eq ""
not defined $directory
$directory eq ""
Truth table33%1/3
not(A) or B
A= not defined $directoryB= $directory eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | if !defined($directory) || $directory eq q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 2 | return $self->_run_git('git', '-C', $directory, 'pull'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 2 | ▶ | sub git_push { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
git_push: called CC=3 SCAR=12.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 2 | my ($self, $directory, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | 2 | ▶ | croak 'git_push requires a repository directory' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $directory or $directory eq ""
MC/DC0%0/2
not defined $directory or $directory eq ""
not defined $directory
$directory eq ""
Truth table33%1/3
not(A) or B
A= not defined $directoryB= $directory eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | if !defined($directory) || $directory eq q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | # Optional arguments deliberately map directly to `git push` arguments. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # The high-level CLI compile workflow uses this to push the complete | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | # committed project to the branch discovered from the Overleaf Git remote. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | # It does not upload selected .tex/.bib files or use the ZIP export as a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | # work tree. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 2 | return $self->_run_git('git', '-C', $directory, 'push', @args); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | ▶ | sub git_remote_add { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
git_remote_add: called CC=4 SCAR=15.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | my ($self, $directory, $project_id, $remote) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 1 | ▶ | $remote ||= 'overleaf'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$remote ||= "overleaf"
MC/DC0%0/1
$remote ||= "overleaf"
$remote
Truth table50%1/2
A
A= $remote
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | ▶ | croak 'git_remote_add requires a repository directory' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $directory or $directory eq ""
MC/DC0%0/2
not defined $directory or $directory eq ""
not defined $directory
$directory eq ""
Truth table33%1/3
not(A) or B
A= not defined $directoryB= $directory eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | if !defined($directory) || $directory eq q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 1 | return $self->_run_git( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 'git', '-C', $directory, 'remote', 'add', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | $remote, $self->git_url($project_id) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | sub bootstrap { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bootstrap: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | $self->_require_experimental; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | $self->_require_session; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my $html = $self->_project_page; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | 0 | my $csrf = _csrf_from_html($html); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | croak 'could not find an Overleaf CSRF token; the session may have expired' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not defined $csrf or $csrf eq ""
MC/DC0%0/2
not defined $csrf or $csrf eq ""
not defined $csrf
$csrf eq ""
Truth table0%0/3
not(A) or B
A= not defined $csrfB= $csrf eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | if !defined($csrf) || $csrf eq q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | $self->csrf($csrf); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | return h2o { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | authenticated => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | csrf => $csrf, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 4 | ▶ | sub projects { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
projects: called CC=21 SCAR=42.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | 4 | $self->_require_experimental; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 3 | $self->_require_session; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 2 | my $html = $self->_project_page; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 1 | my $csrf = _csrf_from_html($html); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 1 | ▶ | $self->csrf($csrf) if defined $csrf && $csrf ne q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $csrf and $csrf ne ""
MC/DC0%0/2
defined $csrf and $csrf ne ""
defined $csrf
$csrf ne ""
Truth table33%1/3
A and B
A= defined $csrfB= $csrf ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | my @meta = _meta_tags($html); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 1 | my $projects; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | # Current Overleaf shape. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | my ($prefetched) = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 1 | ▶ | defined $_->{name} && $_->{name} eq 'ol-prefetchedProjectsBlob' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $_->{'name'} && $_->{'name'} eq 'ol-prefetchedProjectsBlob'
MC/DC50%1/2
defined $_->{'name'} && $_->{'name'} eq 'ol-prefetchedProjectsBlob'
defined $_->{'name'}
$_->{'name'} eq 'ol-prefetchedProjectsBlob'
Truth table66%2/3
A && B
A= defined $_->{'name'}B= $_->{'name'} eq 'ol-prefetchedProjectsBlob'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } @meta; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 1 | ▶ | $projects = _projects_from_json($prefetched->{content}) if $prefetched; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # Intermediate shape: an otherwise-generic meta element containing a | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # JSON object with a projects member. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 1 | ▶ | if (!$projects || !@$projects) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$projects and @$projects
MC/DC0%0/2
$projects and @$projects
$projects
@$projects
Truth table33%1/3
A and B
A= $projectsB= @$projects
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | META: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | for my $m (@meta) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | next if !defined $m->{content}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | next if $m->{content} !~ /["']projects["']/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | my $candidate = _projects_from_json($m->{content}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | if ($candidate) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 0 | $projects = $candidate; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | last META; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | # Legacy shape retained by older/self-hosted releases. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 1 | ▶ | if (!$projects || !@$projects) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$projects and @$projects
MC/DC0%0/2
$projects and @$projects
$projects
@$projects
Truth table33%1/3
A and B
A= $projectsB= @$projects
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | my ($legacy) = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | ▶ | defined $_->{name} && $_->{name} eq 'ol-projects' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
defined $_->{'name'} && $_->{'name'} eq 'ol-projects'
MC/DC0%0/2
defined $_->{'name'} && $_->{'name'} eq 'ol-projects'
defined $_->{'name'}
$_->{'name'} eq 'ol-projects'
Truth table0%0/3
A && B
A= defined $_->{'name'}B= $_->{'name'} eq 'ol-projects'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } @meta; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | $projects = _projects_from_json($legacy->{content}) if $legacy; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 1 | ▶ | $projects ||= []; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$projects ||= []
MC/DC0%0/1
$projects ||= []
$projects
Truth table50%1/2
A
A= $projects
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 1 | my @normalized; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 1 | for my $p (@$projects) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | 3 | ▶ | next if ref($p) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 3 | ▶ | next if $p->{archived} || $p->{trashed}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$p->{"archived"} or $p->{"trashed"}
MC/DC100%2/2
$p->{"archived"} or $p->{"trashed"}
$p->{"archived"}
$p->{"trashed"}
Truth table100%3/3
A or B
A= $p->{"archived"}B= $p->{"trashed"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | push @normalized, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | id => defined $p->{id} ? $p->{id} : $p->{_id}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | name => $p->{name}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | last_updated => $p->{lastUpdated}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | last_updated_by => $p->{lastUpdatedBy}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | owner => $p->{owner}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | ▶ | archived => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | trashed => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 1 | return d2o \@normalized; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 3 | ▶ | sub project_zip { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
project_zip: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 3 | my ($self, $project_id, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 3 | $self->_require_experimental; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 3 | $self->_require_session; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 3 | $project_id = _project_id($project_id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | 3 | my $response = $self->_request( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | 'GET', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | $self->project_url($project_id) . '/download/zip', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | headers => $self->_headers, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | 2 | return _save_or_return($response->{content}, $opts{to}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | 1 | ▶ | sub compile { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
compile: called CC=18 SCAR=36.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 1 | my ($self, $project_id, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | $self->_require_experimental; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 1 | $self->_require_session; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 1 | $project_id = _project_id($project_id); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 1 | $self->_ensure_csrf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | 1 | my %body = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | rootDoc_id => undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | draft => JSON::PP::false, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | check => 'silent', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | incrementalCompilesEnabled => JSON::PP::true, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | $body{rootResourcePath} = $opts{resource_path} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 1 | ▶ | if defined $opts{resource_path} && $opts{resource_path} ne q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $opts{"resource_path"} and $opts{"resource_path"} ne ""
MC/DC0%0/2
defined $opts{"resource_path"} and $opts{"resource_path"} ne ""
defined $opts{"resource_path"}
$opts{"resource_path"} ne ""
Truth table33%1/3
A and B
A= defined $opts{"resource_path"}B= $opts{"resource_path"} ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 1 | my %headers = %{ $self->_headers }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 1 | $headers{'Content-Type'} = 'application/json'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 1 | my $response = $self->_request( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 'POST', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | $self->project_url($project_id) . '/compile?enable_pdf_caching=true', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | headers => \%headers, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | content => encode_json(\%body), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 1 | my $data = eval { decode_json($response->{content}) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | 1 | ▶ | croak 'Overleaf compile response was not valid JSON: ' . ($@ || 'unknown error') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
not $data or ref $data ne "HASH"
$@ || 'unknown error'
MC/DC0%0/2
not $data or ref $data ne "HASH"
not $data
ref $data ne "HASH"
MC/DC0%0/1
$@ || 'unknown error'
$@
Truth table33%1/3
not(A) or B
A= not $dataB= ref $data ne "HASH"
Truth table0%0/2
A
A= $@
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | if !$data || ref($data) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 1 | ▶ | my $status = defined $data->{status} ? $data->{status} : 'error'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | 1 | ▶ | if ($status ne 'success') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | my $hint = defined $opts{resource_path} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | ? ' (the requested resource file may not exist in the project)' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | : q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | croak 'Overleaf compilation failed: ' . $status . $hint; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | my $clsi_qs = defined($data->{clsiServerId}) && $data->{clsiServerId} ne q{} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | ? '?clsiserverid=' . uri_escape_utf8($data->{clsiServerId}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 1 | ▶ | : q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $data->{"clsiServerId"} and $data->{"clsiServerId"} ne ""
MC/DC0%0/2
defined $data->{"clsiServerId"} and $data->{"clsiServerId"} ne ""
defined $data->{"clsiServerId"}
$data->{"clsiServerId"} ne ""
Truth table33%1/3
A and B
A= defined $data->{"clsiServerId"}B= $data->{"clsiServerId"} ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | 1 | my @outputs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 1 | ▶ | for my $f (@{ $data->{outputFiles} || [] }) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$data->{'outputFiles'} || []
MC/DC0%0/1
$data->{'outputFiles'} || []
$data->{'outputFiles'}
Truth table50%1/2
A
A= $data->{'outputFiles'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 3 | ▶ | next if ref($f) ne 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | push @outputs, { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | path => $f->{path}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | type => $f->{type}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | 3 | url => _absolute_url($self->base_url, $f->{url}) . $clsi_qs, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 1 | ▶ | my ($pdf) = grep { defined($_->{path}) && $_->{path} eq 'output.pdf' } @outputs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $_->{'path'} && $_->{'path'} eq 'output.pdf'
MC/DC50%1/2
defined $_->{'path'} && $_->{'path'} eq 'output.pdf'
defined $_->{'path'}
$_->{'path'} eq 'output.pdf'
Truth table66%2/3
A && B
A= defined $_->{'path'}B= $_->{'path'} eq 'output.pdf'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | ($pdf) = grep { defined($_->{type}) && $_->{type} eq 'pdf' } @outputs if !$pdf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $_->{'type'} && $_->{'type'} eq 'pdf'
MC/DC0%0/2
defined $_->{'type'} && $_->{'type'} eq 'pdf'
defined $_->{'type'}
$_->{'type'} eq 'pdf'
Truth table0%0/3
A && B
A= defined $_->{'type'}B= $_->{'type'} eq 'pdf'
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 1 | ▶ | croak 'Overleaf compilation succeeded but no PDF output was returned' if !$pdf; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | return d2o { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | status => $status, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | pdf_url => $pdf->{url}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | compile_group => $data->{compileGroup}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | clsi_server_id => $data->{clsiServerId}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | 1 | output_files => \@outputs, | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | 1 | ▶ | sub download_pdf { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
download_pdf: called CC=5 SCAR=17.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | 1 | my ($self, $project_id, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 1 | $self->_require_experimental; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 1 | $self->_require_session; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 1 | my $compile = delete $opts{compile}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 1 | ▶ | if (!$compile) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | $compile = $self->compile($project_id, %opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 1 | my $pdf_url = eval { $compile->pdf_url }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | 1 | ▶ | $pdf_url = $compile->{pdf_url} if !$pdf_url && ref($compile) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $pdf_url and ref $compile eq "HASH"
MC/DC0%0/2
not $pdf_url and ref $compile eq "HASH"
not $pdf_url
ref $compile eq "HASH"
Truth table33%1/3
not(A) and B
A= not $pdf_urlB= ref $compile eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 1 | ▶ | croak 'compile result does not contain pdf_url' if !defined $pdf_url; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 1 | my $response = $self->_request( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 'GET', $pdf_url, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | headers => $self->_headers, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | 1 | return _save_or_return($response->{content}, $opts{to}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 1 | ▶ | sub download_output { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
download_output: called CC=15 SCAR=31.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 1 | my ($self, $compile, $path, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 1 | $self->_require_experimental; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 1 | $self->_require_session; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 1 | ▶ | croak 'download_output requires a compile result and output path' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$compile and defined $path
MC/DC0%0/2
$compile and defined $path
$compile
defined $path
Truth table33%1/3
A and B
A= $compileB= defined $path
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | if !$compile || !defined $path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 1 | my $files = eval { $compile->output_files }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | 1 | ▶ | $files = $compile->{output_files} if !$files && ref($compile) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $files and ref $compile eq "HASH"
MC/DC0%0/2
not $files and ref $compile eq "HASH"
not $files
ref $compile eq "HASH"
Truth table33%1/3
not(A) and B
A= not $filesB= ref $compile eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 1 | ▶ | croak 'compile result does not contain output_files' if !$files; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 1 | ▶ | my @files = ref($files) eq 'ARRAY' ? @$files : eval { $files->all }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | my ($file) = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | 1 | my $p = eval { $_->path }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | 3 | ▶ | $p = $_->{path} if !defined($p) && ref($_) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $p and ref $_ eq "HASH"
MC/DC0%0/2
not defined $p and ref $_ eq "HASH"
not defined $p
ref $_ eq "HASH"
Truth table33%1/3
not(A) and B
A= not defined $pB= ref $_ eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 3 | ▶ | defined($p) && $p eq $path; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
defined $p && $p eq $path
MC/DC50%1/2
defined $p && $p eq $path
defined $p
$p eq $path
Truth table66%2/3
A && B
A= defined $pB= $p eq $path
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | } @files; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | 1 | ▶ | croak "compile output '$path' was not found" if !$file; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 1 | my $url = eval { $file->url }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | 1 | ▶ | $url = $file->{url} if !defined($url) && ref($file) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $url and ref $file eq "HASH"
MC/DC0%0/2
not defined $url and ref $file eq "HASH"
not defined $url
ref $file eq "HASH"
Truth table33%1/3
not(A) and B
A= not defined $urlB= ref $file eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | 1 | ▶ | croak "compile output '$path' does not contain a URL" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $url or $url eq ""
MC/DC0%0/2
not defined $url or $url eq ""
not defined $url
$url eq ""
Truth table33%1/3
not(A) or B
A= not defined $urlB= $url eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | if !defined($url) || $url eq q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | 1 | my $response = $self->_request( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 'GET', $url, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | headers => $self->_headers, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 1 | return _save_or_return($response->{content}, $opts{to}); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 3 | ▶ | sub call { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
call: called CC=1 SCAR=1.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 3 | my ($self, $operation, @args) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 3 | my $input = [ $operation, @args ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 3 | ▶ | return dispatch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 3 | my ($op) = xshift_and_deref @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | 3 | return xdefault $op; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | $input, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 1 | ▶ | on open_uri => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 1 | my ($op, @a) = xshift_and_deref @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | 1 | return $self->open_uri(@a); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 0 | ▶ | on open_data => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | 0 | my ($op, @a) = xshift_and_deref @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 0 | return $self->open_data(@a); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | 1 | ▶ | on git_url => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | 1 | my ($op, @a) = xshift_and_deref @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 1 | return $self->git_url(@a); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | ▶ | on git_clone => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | my ($op, @a) = xshift_and_deref @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 0 | return $self->git_clone(@a); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | ▶ | on git_pull => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 0 | my ($op, @a) = xshift_and_deref @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 0 | return $self->git_pull(@a); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 0 | ▶ | on git_push => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | my ($op, @a) = xshift_and_deref @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | return $self->git_push(@a); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | on projects => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 0 | my ($op, @a) = xshift_and_deref @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | return $self->projects(@a); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | on project_zip => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | my ($op, @a) = xshift_and_deref @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | 0 | return $self->project_zip(@a); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | on compile => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | my ($op, @a) = xshift_and_deref @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 0 | return $self->compile(@a); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | 0 | ▶ | on download_pdf => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | my ($op, @a) = xshift_and_deref @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | return $self->download_pdf(@a); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 1 | ▶ | on default => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 1 | my ($op) = xshift_and_deref @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 1 | croak "unsupported Overleaf operation '$op'"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | 3 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | 2 | ▶ | sub _project_page { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_project_page: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 2 | my $response = $self->_request( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 'GET', $self->base_url . '/project', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | headers => $self->_headers, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 1 | return $response->{content}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 1 | ▶ | sub _ensure_csrf { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_ensure_csrf: called CC=3 SCAR=14.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 1 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | 1 | ▶ | return $self->csrf if defined($self->csrf) && $self->csrf ne q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->csrf and $self->csrf ne ""
MC/DC0%0/2
defined $self->csrf and $self->csrf ne ""
defined $self->csrf
$self->csrf ne ""
Truth table33%1/3
A and B
A= defined $self->csrfB= $self->csrf ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | 0 | return $self->bootstrap->csrf; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 8 | ▶ | sub _headers { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_headers: called CC=5 SCAR=17.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 8 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | 8 | my %headers = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 'User-Agent' => 'Webservice-Overleaf-API/' . $VERSION, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 8 | ▶ | $headers{Cookie} = $self->cookie_name . '=' . $self->session | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $self->session and $self->session ne ""
MC/DC0%0/2
defined $self->session and $self->session ne ""
defined $self->session
$self->session ne ""
Truth table33%1/3
A and B
A= defined $self->sessionB= $self->session ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | if defined($self->session) && $self->session ne q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 8 | ▶ | $headers{'X-Csrf-Token'} = $self->csrf | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $self->csrf and $self->csrf ne ""
MC/DC50%1/2
defined $self->csrf and $self->csrf ne ""
defined $self->csrf
$self->csrf ne ""
Truth table66%2/3
A and B
A= defined $self->csrfB= $self->csrf ne ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | if defined($self->csrf) && $self->csrf ne q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 8 | return \%headers; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | 8 | ▶ | sub _request { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_request: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 8 | my ($self, $method, $url, %opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 8 | my $ua = $self->ua; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 8 | ▶ | if (!$ua) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 0 | $ua = HTTP::Tiny->new( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | agent => 'Webservice-Overleaf-API/' . $VERSION, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | timeout => $self->timeout, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | $self->ua($ua); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | 8 | my $response = $ua->request($method, $url, \%opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | 8 | $self->last_response($response); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 8 | ▶ | return dispatch { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 8 | my $r = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | 8 | ▶ | return 'ok' if $r->{success}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | 2 | ▶ | return 'auth' if defined($r->{status}) && ($r->{status} == 401 || $r->{status} == 403); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%4/6
defined $r->{"status"} and $r->{"status"} == 401 || $r->{"status"} == 403
$r->{"status"} == 401 or $r->{"status"} == 403
MC/DC33%1/3
defined $r->{"status"} and $r->{"status"} == 401 || $r->{"status"} == 403
defined $r->{"status"}
$r->{"status"} == 401
$r->{"status"} == 403
Truth table50%2/4
A and B or C
A= defined $r->{"status"}B= $r->{"status"} == 401C= $r->{"status"} == 403
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | 1 | return 'http'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | $response, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 6 | ▶ | on ok => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 6 | return shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | 1 | ▶ | on auth => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 1 | my $r = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 1 | croak 'Overleaf authentication failed (HTTP ' . $r->{status} . '); the session may have expired'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | 1 | ▶ | on http => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=12.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 1 | my $r = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | croak 'Overleaf request failed: HTTP ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | . (defined($r->{status}) ? $r->{status} : '?') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | . ' ' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 1 | ▶ | . (defined($r->{reason}) ? $r->{reason} : q{}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | 8 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | 6 | ▶ | sub _run_git { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_run_git: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | 6 | my ($self, @cmd) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 6 | my $exit = $self->git_runner->(@cmd); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | 6 | ▶ | croak 'git command failed with exit status ' . $exit . ': ' . join(' ', @cmd) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | if $exit; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 5 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 0 | ▶ | sub _default_git_runner { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_default_git_runner: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | my @cmd = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | system { $cmd[0] } @cmd; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | ▶ | return $? == -1 ? 255 : ($? >> 8); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 10 | ▶ | sub _require_experimental { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_require_experimental: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 10 | ▶ | croak 'this method uses Overleaf\'s undocumented web application interface; construct with experimental => 1 to enable it' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | if !$self->experimental; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | 9 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 9 | ▶ | sub _require_session { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_require_session: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | 9 | ▶ | croak 'an Overleaf session cookie is required (session => ... or OVERLEAF_SESSION)' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $self->session or $self->session eq ""
MC/DC50%1/2
not defined $self->session or $self->session eq ""
not defined $self->session
$self->session eq ""
Truth table66%2/3
not(A) or B
A= not defined $self->sessionB= $self->session eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | if !defined($self->session) || $self->session eq q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | 8 | return 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | 17 | ▶ | sub _project_id { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_project_id: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | 17 | my $id = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | 17 | ▶ | croak 'project id is required' if !defined($id) || $id eq q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $id or $id eq ""
MC/DC0%0/2
not defined $id or $id eq ""
not defined $id
$id eq ""
Truth table33%1/3
not(A) or B
A= not defined $idB= $id eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 17 | ▶ | croak 'invalid project id' if $id !~ /\A[A-Za-z0-9_-]+\z/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | 16 | return $id; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | 8 | ▶ | sub _append_open_features { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_append_open_features: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | 8 | my ($pairs, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | 8 | ▶ | if (exists $opts->{engine}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 4 | my $engine = delete $opts->{engine}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | 4 | my %valid = map { $_ => 1 } qw/latex_dvipdf pdflatex xelatex lualatex/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | 4 | ▶ | croak "unsupported TeX engine '$engine'" if !$valid{$engine}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 3 | push @$pairs, [ engine => $engine ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | 7 | ▶ | if (exists $opts->{main_document}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | 2 | push @$pairs, [ main_document => delete $opts->{main_document} ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 7 | ▶ | if (exists $opts->{visual_editor}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | 1 | ▶ | push @$pairs, [ visual_editor => delete($opts->{visual_editor}) ? 'true' : 'false' ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | 7 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | 1 | ▶ | sub _append_open_features_hash { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_append_open_features_hash: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | 1 | my ($fields, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 1 | my @pairs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 1 | _append_open_features(\@pairs, $opts); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | 1 | $fields->{ $_->[0] } = $_->[1] for @pairs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | 6 | ▶ | sub _query_string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_query_string: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 6 | my @pairs = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | return join '&', map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | 6 | ▶ | uri_escape_utf8($_->[0]) . '=' . uri_escape_utf8(defined($_->[1]) ? $_->[1] : q{}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | } @pairs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 4 | ▶ | sub _attrs { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_attrs: called CC=4 SCAR=14.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 4 | my $text = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | 4 | my %attrs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 4 | ▶ | while ($text =~ /([A-Za-z_:][-A-Za-z0-9_:.]*)\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s>]+))/g) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 8 | my ($key, $dq, $sq, $bare) = ($1, $2, $3, $4); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | 8 | ▶ | my $value = defined($dq) ? $dq : defined($sq) ? $sq : $bare; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | 8 | $attrs{lc $key} = decode_entities($value); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 4 | return \%attrs; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 2 | ▶ | sub _meta_tags { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_meta_tags: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | 2 | my $html = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | 2 | my @meta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | 2 | ▶ | while ($html =~ /<meta\b([^>]*)>/ig) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 4 | push @meta, _attrs($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | 2 | return @meta; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | 1 | ▶ | sub _csrf_from_html { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_csrf_from_html: called CC=10 SCAR=40.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 1 | my $html = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | 1 | for my $meta (_meta_tags($html)) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | return $meta->{content} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | if defined($meta->{name}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | && $meta->{name} eq 'ol-csrfToken' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | 1 | ▶ | && defined($meta->{content}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
defined $meta->{"name"} and $meta->{"name"} eq "ol-csrfToken" and defined $meta->{"content"}
defined $meta->{"name"} and $meta->{"name"} eq "ol-csrfToken"
MC/DC0%0/3
defined $meta->{"name"} and $meta->{"name"} eq "ol-csrfToken" and defined $meta->{"content"}
defined $meta->{"name"}
$meta->{"name"} eq "ol-csrfToken"
defined $meta->{"content"}
Truth table25%1/4
A and B and C
A= defined $meta->{"name"}B= $meta->{"name"} eq "ol-csrfToken"C= defined $meta->{"content"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | ▶ | while ($html =~ /<input\b([^>]*)>/ig) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | 0 | my $attrs = _attrs($1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | return $attrs->{value} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | if defined($attrs->{name}) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | && $attrs->{name} eq '_csrf' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | ▶ | && defined($attrs->{value}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
defined $attrs->{"name"} and $attrs->{"name"} eq "_csrf" and defined $attrs->{"value"}
defined $attrs->{"name"} and $attrs->{"name"} eq "_csrf"
MC/DC0%0/3
defined $attrs->{"name"} and $attrs->{"name"} eq "_csrf" and defined $attrs->{"value"}
defined $attrs->{"name"}
$attrs->{"name"} eq "_csrf"
defined $attrs->{"value"}
Truth table0%0/4
A and B and C
A= defined $attrs->{"name"}B= $attrs->{"name"} eq "_csrf"C= defined $attrs->{"value"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | ▶ | if ($html =~ /csrfToken["']?\s*[:=]\s*["']([^"']+)["']/) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | 0 | return $1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | 1 | ▶ | sub _projects_from_json { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_projects_from_json: called CC=8 SCAR=26.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | 1 | my $text = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | 1 | ▶ | return if !defined($text) || $text eq q{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not defined $text or $text eq ""
MC/DC0%0/2
not defined $text or $text eq ""
not defined $text
$text eq ""
Truth table33%1/3
not(A) or B
A= not defined $textB= $text eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 1 | my $data = eval { decode_json($text) }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 1 | ▶ | return if $@ || !defined $data; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$@ or not defined $data
MC/DC0%0/2
$@ or not defined $data
$@
not defined $data
Truth table33%1/3
A or not(B)
A= $@B= not defined $data
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | 1 | ▶ | return $data if ref($data) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 1 | ▶ | return $data->{projects} if ref($data) eq 'HASH' && ref($data->{projects}) eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
ref $data eq "HASH" and ref $data->{"projects"} eq "ARRAY"
MC/DC0%0/2
ref $data eq "HASH" and ref $data->{"projects"} eq "ARRAY"
ref $data eq "HASH"
ref $data->{"projects"} eq "ARRAY"
Truth table33%1/3
A and B
A= ref $data eq "HASH"B= ref $data->{"projects"} eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | 3 | ▶ | sub _absolute_url { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_absolute_url: called CC=4 SCAR=15.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | 3 | my ($base, $url) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 3 | ▶ | return q{} if !defined $url; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | 3 | ▶ | return $url if $url =~ m{\Ahttps?://}i; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 3 | ▶ | return $base . $url if $url =~ m{\A/}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | 0 | return $base . '/' . $url; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | 4 | ▶ | sub _save_or_return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_save_or_return: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | 4 | my ($content, $to) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 4 | ▶ | return $content if !defined $to; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | 1 | ▶ | open my $fh, '>:raw', $to or croak "could not write '$to': $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | 1 | print {$fh} $content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | 1 | ▶ | close $fh or croak "could not close '$to': $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | 1 | return $to; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||