lib/LaTeXML/Util/WWW.pm

filter: Statementstmt 37.6% 26 / 69 Branchbran 0.0% 0 / 28 Conditioncond 0.0% 0 / 18 MC/DCmcdc 0.0% 0 / 9 Subroutinesub 72.7% 8 / 11 Podpod 33.3% 1 / 3 totaltotal 25.3% 35 / 138 CC 21 SCAR 45.6
CC
21
Cov
23%
auth_get
182.0
url_find
72.0
url_split
6.0
CRAP 95.5
« lib/LaTeXML/MathParser.pm ↑ Summary lib/LaTeXML/Core/Box.pm »
1 # /=====================================================================\ #
2 # | LaTeXML::Util::WWW | #
3 # | Web Utilities for LaTeXML | #
4 # |=====================================================================| #
5 # | Part of LaTeXML: | #
6 # | Public domain software, produced as part of work done by the | #
7 # | United States Government & not subject to copyright in the US. | #
8 # |---------------------------------------------------------------------| #
9 # | Deyan Ginev (d.ginev@jacobs-university.de) #_# | #
10 # | http://dlmf.nist.gov/LaTeXML/ (o o) | #
11 # \=========================================================ooo==U==ooo=/ #
12  
13 package LaTeXML::Util::WWW;
14 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use LaTeXML::Common::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use LaTeXML::Global;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use LWP;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 5 ▶use LWP::Simple;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 5 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
22 5 our @EXPORT = qw(&auth_get &url_find &url_split);
23  
24 0 ▶sub auth_get {
Subroutine auth_get: not called CC=13 SCAR=52.0
Pod documented
25 0 my ($url, $authlist) = @_;
26 0 my $browser;
27 0 ▶ if ($url =~ /^https/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url =~ /^https/) { } 0 0 0
28 0 $browser = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 }); }
29 else {
30 0 $browser = LWP::UserAgent->new; }
31 0 my $response = $browser->get($url);
32 0 my $realm = $response->www_authenticate;
33 0 ▶ if ($realm) {
Branch: 1 branch
BranchTrueFalseTotal
if ($realm) 0 0 0
34 0 ▶ if ($realm =~ /^Basic realm="([^"]+)"$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($realm =~ /^Basic realm="([^"]+)"$/) 0 0 0
35 0 $realm = $1; }
36 # Prompt for username pass for this location:
37 0 my $req; my $tries = 2;
38 0 ▶ my ($uname, $pass) = ($$authlist{$realm} ? @{ $$authlist{$realm} } : (undef, undef));
Branch: 1 branch
BranchTrueFalseTotal
$authlist->{$realm} ? : 0 0 0
39 0 ▶ while (!($response && $response->is_success) && $tries > 0) { # 2 tries
Branch: 1 branch
BranchTrueFalseTotal
if (not $response && $response->is_success and $tries > 0) 0 0 0
Condition0%0/6
not $response && $response->is_success and $tries > 0
!ll&&!rl&&r
000
$response && $response->is_success
!ll&&!rl&&r
000
MC/DC0%0/3
not $response && $response->is_success and $tries > 0
$response $response->is_success $tries > 0
Truth table0%0/5
not(A && B) and C
A= $responseB= $response->is_successC= $tries > 0
ABCresult
11X0
0X00
1000
0X11
1011
40 0 $tries--;
41 0 ▶ if (!$uname) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $uname) { } 0 0 0
42 0 $req = HTTP::Request->new(GET => $url);
43 0 $req->authorization_basic($uname, $pass);
44 0 $response = $browser->request($req);
45 0 ▶ $$authlist{$realm} = [$uname, $pass] if $response->is_success; }
Branch: 1 branch
BranchTrueFalseTotal
if $response->is_success 0 0 0
46 else {
47 0 $req = HTTP::Request->new(GET => $url);
48 0 $req->authorization_basic($uname, $pass);
49 0 $response = $browser->request($req); } } }
50 0 ▶ return auth_get("$url.tex", $authlist) if ((!$response->is_success) && $url !~ /\.tex$/);
Branch: 1 branch
BranchTrueFalseTotal
unless $response->is_success or $url =~ /\.tex$/ 0 0 0
Condition0%0/3
$response->is_success or $url =~ /\.tex$/
l!l&&r!l&&!r
000
MC/DC0%0/2
$response->is_success or $url =~ /\.tex$/
$response->is_success $url =~ /\.tex$/
Truth table0%0/3
A or B
A= $response->is_successB= $url =~ /\.tex$/
ABresult
1X1
011
000
51 0 ▶ Error('www', 'get', $url, 'HTTP GET failed with: "' . $response->message . '"') unless ($response->is_success);
Branch: 1 branch
BranchTrueFalseTotal
unless $response->is_success 0 0 0
52 0 return $response->content; }
53  
54 0 ▶sub url_find {
Subroutine url_find: not called CC=8 SCAR=42.8
Pod undocumented
55 0 my ($relative_url, %options) = @_;
56 return if !($options{urlbase} && $relative_url &&
57 0 ▶ length($options{urlbase}) > 0 && length($relative_url) > 0);
Branch: 1 branch
BranchTrueFalseTotal
unless $options{"urlbase"} and $relative_url and length $options{"urlbase"} > 0 and length $relative_url > 0 0 0 0
Condition0%0/9
$options{"urlbase"} and $relative_url and length $options{"urlbase"} > 0 and length $relative_url > 0
!ll&&!rl&&r
000
$options{"urlbase"} and $relative_url and length $options{"urlbase"} > 0
!ll&&!rl&&r
000
$options{"urlbase"} and $relative_url
!ll&&!rl&&r
000
MC/DC0%0/4
$options{"urlbase"} and $relative_url and length $options{"urlbase"} > 0 and length $relative_url > 0
$options{"urlbase"} $relative_url length $options{"urlbase"} > 0 length $relative_url > 0
Truth table0%0/5
A and B and C and D
A= $options{"urlbase"}B= $relative_urlC= length $options{"urlbase"} > 0D= length $relative_url > 0
ABCDresult
0XXX0
10XX0
110X0
11100
11111
58 0 $options{urlbase} =~ s/(\/+)$//g;
59 0 $options{urlbase} .= '/';
60 0 my $absolute_url = URI->new_abs($relative_url, $options{urlbase});
61 0 my $browser;
62 0 ▶ if ($absolute_url =~ /^https/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($absolute_url =~ /^https/) { } 0 0 0
63 0 $browser = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 }); }
64 else {
65 0 $browser = LWP::UserAgent->new; }
66 0 my $response = $browser->head($absolute_url);
67 0 ▶ if ($response->is_success) {
Branch: 1 branch
BranchTrueFalseTotal
if ($response->is_success) { } 0 0 0
68 0 return $absolute_url->as_string }
69 else {
70 # Only 404 is expected, anythign else is an error:
71 0 ▶ Error("http_fail", $response->code, undef, " HTTP GET on $absolute_url failed. Reason: " . $response->message) if ($response->code != 404);
Branch: 1 branch
BranchTrueFalseTotal
if $response->code != 404 0 0 0
72 0 return; } }
73  
74 0 ▶sub url_split {
Subroutine url_split: not called CC=2 SCAR=17.9
Pod undocumented
75 0 my ($url) = @_;
76 0 ▶ return ($url =~ /^(.+)\/([^\/]+)$/ ? ($1, $2) : ($url, 'index.tex')); } # Well, what????
Branch: 1 branch
BranchTrueFalseTotal
$url =~ m[^(.+)/([^/]+)$] ? : 0 0 0
77  
78 #======================================================================
79 5 1;
80  
81 __END__
« lib/LaTeXML/MathParser.pm ↑ Summary lib/LaTeXML/Core/Box.pm »