PerlDistSite/MenuItem/Pod.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 45 SCAR 24.8
CC
3
Cov
0%
_build_raw_content
12.0
body_class
2.0
write_page
2.0
CRAP 12.0
1 package Web::PerlDistSite::MenuItem::Pod;
2  
3 our $VERSION = '0.001010';
4  
5 use Moo;
6 use Web::PerlDistSite::Common -lexical, -all;
7  
8 use Pod::Find qw( pod_where );
9  
10 extends 'Web::PerlDistSite::MenuItem';
11 with 'Web::PerlDistSite::MenuItem::_PodCommon';
12  
13 has '+title' => (
14 is       => 'lazy',
15 default  => sub ( $s ) {
16 $s->pod;
17 },
18 );
19  
20 has '+name' => (
21 is       => 'lazy',
22 default  => sub ( $s ) {
23 $s->pod =~ s{::}{-}gr;
24 },
25 );
26  
27 has pod => (
28 is       => 'ro',
29 isa      => Str,
30 );
31  
32 has raw_content => (
33 is       => 'lazy',
34 isa      => Str,
35 builder  => true,
36 );
37  
38 sub body_class {
39 return 'page from-pod';
40 }
41  
42 sub _build_raw_content ( $self ) {
43
44 my $local = pod_where( { -inc => true }, $self->pod );
45 return path( $local )->slurp_utf8 if $local;
46
47 require HTTP::Tiny;
48 state $ua = HTTP::Tiny->new;
49 my $response = $ua->get( sprintf(
50 'https://fastapi.metacpan.org/v1/pod/%s?content-type=text/x-pod',
51 $self->pod,
52 ) );
53 return $response->{content} if $response->{success};
54
55 die sprintf( "pod not found: %s\n", $self->pod );
56 }
57  
58 sub write_page ( $self ) {
59 $self->system_path->parent->mkpath;
60 $self->system_path->spew_if_changed( $self->compile_page );
61 }
62  
63 1;