lib/Chj/CPAN/ModulePODUrl.pm

filter: Statementstmt 58.9% 23 / 39 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 54.5% 6 / 11 Podpod 0.0% 0 / 2 totaltotal 51.7% 29 / 56 CC 3 SCAR 13.5
CC
3
Cov
53%
if_get
12.0
perhaps_module_pod_url
2.0
__ANON__
2.0
CRAP 3.8
« lib/FP/Array/Mixin.pm ↑ Summary examples/csv-to-json »
1 #
2 # Copyright (c) 2015-2019 Christian Jaeger, copying@christianjaeger.ch
3 #
4 # This is free software, offered under either the same terms as perl 5
5 # or the terms of the Artistic License version 2 or the terms of the
6 # MIT License (Expat version). See the file COPYING.md that came
7 # bundled with this file.
8 #
9  
10 =head1 NAME
11  
12 Chj::CPAN::ModulePODUrl - get module POD url on metacpan
13  
14 =head1 SYNOPSIS
15  
16 use Chj::CPAN::ModulePODUrl "perhaps_module_pod_url";
17  
18 is_equal [perhaps_module_pod_url "Test::More"],
19 ['https://metacpan.org/pod/Test::More'];
20  
21 is_equal [perhaps_module_pod_url "SomeNonexisting::Module12345"],
22 [];
23  
24  
25 =head1 DESCRIPTION
26  
27  
28 =head1 NOTE
29  
30 This is alpha software! Read the status section in the package README
31 or on the L<website|http://functional-perl.org/>.
32  
33 =cut
34  
35 package Chj::CPAN::ModulePODUrl;
36 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
38 3 ▶use warnings FATAL => 'uninitialized';
Subroutine BEGIN: called CC=1 SCAR=0.0
39 3 ▶use Exporter "import";
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 3 our @EXPORT = qw(perhaps_module_pod_url);
42 3 our @EXPORT_OK = qw(if_get);
43 3 our %EXPORT_TAGS = (all => [@EXPORT, @EXPORT_OK]);
44  
45 3 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
46 3 ▶use FP::Show;
Subroutine BEGIN: called CC=1 SCAR=0.0
47  
48 3 our $ua = LWP::UserAgent->new; # reuse to speed up HTTPS handling?
49  
50 #$ua->timeout($maybe_timeout);
51 #$ua->env_proxy;
52  
53 0 ▶sub if_get ($&&&) {
Subroutine if_get: not called CC=3 SCAR=24.8
Pod undocumented
54  
55 # the handlers are getting a HTTP::Response object
56 0 my ($url, $success, $res404, $error) = @_;
57  
58 0 my $response = $ua->get($url);
59  
60 0 do {
61 0 ▶ if ($response->is_success) {
Branch: 2 branches
BranchTrueFalseTotal
if ($response->is_success) { } 0 0 0
elsif ($response->code == 404) { } 0 0 0
62 0 $success
63 } elsif ($response->code == 404) {
64 0 $res404
65 } else {
66  
67 # XX todo: handle redirects transparently?
68 0 $error
69 }
70 }
71 ->($response)
72 }
73  
74 #sub if_module_pod_url ($&&&) {
75 # my ($module_name,$then,$else,$error) = @_;
76  
77 # better for caching (also perhaps in general): return error object?
78 # Or even just plain old die.
79  
80 0 ▶sub perhaps_module_pod_url {
Subroutine perhaps_module_pod_url: not called CC=1 SCAR=6.9
Pod undocumented
81 0 my ($module_name) = @_;
82  
83 0 my $url = "https://metacpan.org/pod/$module_name";
84  
85 if_get(
86 $url,
87 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
88 0 my ($response) = @_;
89 0 ($url)
90 },
91 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
92 0 my ($response) = @_;
93 ()
94 0 },
95 0 ▶ sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
96 0 my ($response) = @_;
97 0 die $response->status_line
98 }
99 )
100 0 }
101  
102 3 1
« lib/FP/Array/Mixin.pm ↑ Summary examples/csv-to-json »