File Coverage

lib/Pod/Elemental/Transformer/Splint/Util.pm
Criterion Covered Total %
statement 38 65 58.4
branch 6 20 30.0
condition 1 3 33.3
subroutine 8 10 80.0
pod 0 4 0.0
total 53 102 51.9


line stmt bran cond sub pod time code
1 3     3   15942 use 5.10.1;
  3         15  
2 3     3   27 use strict;
  3         6  
  3         68  
3 3     3   16 use warnings;
  3         5  
  3         186  
4              
5             package Pod::Elemental::Transformer::Splint::Util;
6              
7             # ABSTRACT: Role for attribute renderers
8             our $AUTHORITY = 'cpan:CSSON'; # AUTHORITY
9             our $VERSION = '0.1202';
10              
11 3     3   25 use Moose::Role;
  3         6  
  3         27  
12 3     3   19415 use Pod::Simple::XHTML;
  3         129858  
  3         118  
13 3     3   26 use Safe::Isa;
  3         7  
  3         2660  
14              
15             sub parse_pod {
16 4     4 0 75 my $self = shift;
17 4         7 my $pod = shift;
18              
19 4         32 my $podder = Pod::Simple::XHTML->new;
20 4         444 $podder->html_header('');
21 4         41 $podder->html_footer('');
22 4         20 my $results = '';
23 4         18 $podder->output_string(\$results);
24 4         1434 $podder->parse_string_document("=pod\n\n$pod");
25              
26 4         4198 $results =~ s{</?p>}{}g;
27 4         80 $results =~ s{https?://search\.cpan\.org/perldoc\?}{https://metacpan.org/pod/}g;
28 4         25 $results =~ s{[\v\h]*$}{};
29 4         116 return $results;
30             }
31              
32             sub determine_type_library {
33 0     0 0 0 my $self = shift;
34 0         0 my $type_constraint = shift;
35              
36 0 0       0 return $self->get_library_for_type($type_constraint) if $self->get_library_for_type($type_constraint);
37 0 0       0 return $self->default_type_library if $self->has_default_type_library;
38 0         0 return $type_constraint;
39             }
40              
41             sub make_type_string {
42 1     1 0 56 my $self = shift;
43 1         3 my $type_constraint = shift;
44 1 50       4 return '' if !defined $type_constraint;
45              
46             # The type knows its own library
47 1 50 33     7 return $self->parse_pod(sprintf 'L<%s|%s/"%s>', $type_constraint, $type_constraint->library, $type_constraint) if $type_constraint->$_can('library') && defined $type_constraint->library;
48              
49             # We don't deal with InstanceOf
50 1 50       37 if($type_constraint =~ m{InstanceOf}) {
51 0 0       0 if($self->has_default_type_library) {
52 0         0 $type_constraint =~ s{InstanceOf}{$self->type_string_helper('InstanceOf', $self->default_type_library, 'InstanceOf')}egi;
  0         0  
53 0         0 $type_constraint =~ s{"}{'}g;
54             }
55 0         0 return $type_constraint
56             }
57              
58             # If there are multiple types we deal with them individually
59 1 50       48 if($type_constraint =~ m{[^a-z0-9_]}i) {
60              
61 0         0 $type_constraint =~ s{\b([a-z0-9_]+)\b}{$self->type_string_helper($1, $self->determine_type_library($1), $1)}egi;
  0         0  
62              
63             # cleanup and ensure some whitespace
64 0         0 $type_constraint =~ s{\v}{}g;
65 0         0 $type_constraint =~ s{\|}{ | }g;
66 0         0 $type_constraint =~ s{\[}{ [ }g;
67 0         0 $type_constraint =~ s{]}{ ]}g;
68 0         0 return $type_constraint;
69             }
70              
71              
72             # it can't do library, but it can do name?
73 1 50       38 if($self->$_can('name')) {
74 0         0 my $name = $type_constraint->name;
75              
76 0 0       0 if($self->get_library_for_type($name)) {
77 0         0 return $self->parse_pod(sprintf 'L<%s|%s/"%s>', $name, $self->get_library_for_type($name), $name);
78             }
79 0         0 return $self->parse_pod(sprintf 'L<%s|%s/"%s>', $name, $self->has_default_type_library, $name);
80             }
81              
82 1 50       68 if($self->get_library_for_type($type_constraint)) {
83 0         0 return $self->parse_pod(sprintf 'L<%s|%s/"%s>', $type_constraint, $self->get_library_for_type($type_constraint), $type_constraint);
84             }
85              
86 1         83 return $self->parse_pod(sprintf 'L<%s|%s/"%s>', $type_constraint, $self->has_default_type_library, $type_constraint);
87             }
88              
89             sub type_string_helper {
90 0     0 0   my $self = shift;
91 0           my $text = shift;
92 0           my $type_library = shift;
93 0           my $anchor = shift;
94              
95 0           return $self->parse_pod(sprintf 'L<%s|%s/"%s>', $text, $type_library, $anchor);
96             }
97              
98             1;
99              
100             __END__
101              
102             =pod
103              
104             =encoding UTF-8
105              
106             =head1 NAME
107              
108             Pod::Elemental::Transformer::Splint::Util - Role for attribute renderers
109              
110             =head1 VERSION
111              
112             Version 0.1202, released 2020-12-26.
113              
114             =head1 SOURCE
115              
116             L<https://github.com/Csson/p5-Pod-Elemental-Transformer-Splint>
117              
118             =head1 HOMEPAGE
119              
120             L<https://metacpan.org/release/Pod-Elemental-Transformer-Splint>
121              
122             =head1 AUTHOR
123              
124             Erik Carlsson <info@code301.com>
125              
126             =head1 COPYRIGHT AND LICENSE
127              
128             This software is copyright (c) 2016 by Erik Carlsson.
129              
130             This is free software; you can redistribute it and/or modify it under
131             the same terms as the Perl 5 programming language system itself.
132              
133             =cut