blib/lib/Web/MREST/Util.pm

filter: Statementstmt 86.3% 38 / 44 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.9% 10 / 11 Podpod 100% 2 / 2 totaltotal 87.7% 50 / 57 CC 1 SCAR 0.9
CC
1
Cov
86%
pod_to_text
2.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« blib/lib/Web/MREST/WebServicesIntro.pm ↑ Summary blib/lib/Web/MREST/Test/503.pm »
1 # *************************************************************************
2 # Copyright (c) 2014-2015-2015, SUSE LLC
3 #
4 # All rights reserved.
5 #
6 # Redistribution and use in source and binary forms, with or without
7 # modification, are permitted provided that the following conditions are met:
8 #
9 # 1. Redistributions of source code must retain the above copyright notice,
10 # this list of conditions and the following disclaimer.
11 #
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 #
16 # 3. Neither the name of SUSE LLC nor the names of its contributors may be
17 # used to endorse or promote products derived from this software without
18 # specific prior written permission.
19 #
20 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
24 # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 # POSSIBILITY OF SUCH DAMAGE.
31 # *************************************************************************
32  
33 package Web::MREST::Util;
34  
35 22 ▶use 5.012;
Subroutine BEGIN: called CC=1 SCAR=0.0
36 22 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
37 22 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 22 ▶use App::CELL qw( $log );
Subroutine BEGIN: called CC=1 SCAR=0.0
40 22 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
41 22 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
42 22 ▶use Pod::Simple::HTML;
Subroutine BEGIN: called CC=1 SCAR=0.0
43 22 ▶use Pod::Simple::Text;
Subroutine BEGIN: called CC=1 SCAR=0.0
44  
45  
46 22 our $JSON = JSON->new->allow_nonref->convert_blessed->utf8->pretty;
47  
48  
49  
50 =head1 NAME
51  
52 Web::MREST::Util - Miscellaneous utilities
53  
54  
55  
56  
57 =head1 SYNOPSIS
58  
59 Miscellaneous utilities
60  
61  
62  
63  
64  
65 =head1 EXPORTS
66  
67 This module provides the following exports:
68  
69 =over
70  
71 =item C<$JSON> (singleton)
72  
73 =item C<pod_to_html> (function)
74  
75 =item C<pod_to_text> (function)
76  
77 =back
78  
79 =cut
80  
81 22 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
82 22 our @EXPORT_OK = qw( $JSON pod_to_html pod_to_text );
83  
84  
85  
86  
87 =head1 FUNCTIONS
88  
89  
90 =head2 pod_to_html
91  
92 Every L<Web::MREST> resource definition includes a 'documentation'
93 property containing a POD string. Our 'docu/html' resource converts this
94 POD string into HTML with a little help from this routine.
95  
96 =cut
97  
98 sub pod_to_html {
99 1 ▶ my ( $pod_str ) = @_;
Subroutine pod_to_html: called CC=1 SCAR=0.0
Pod documented
100 1 $log->debug( "Entering " . __PACKAGE__ . "::pod_to_html" );
101  
102 #$log->debug( "pod_to_html before: $pod_str" );
103 1 my $p = Pod::Simple::HTML->new;
104 1 $p->output_string(\my $html_str);
105 1 $p->parse_string_document($pod_str);
106  
107 # now $html_str contains a full-blown HTML file, of which only one part is
108 # of interest to us. That part starts with the line <!-- start doc --> and
109 # ends with <!-- end doc -->
110  
111 1 $html_str =~ s/.*<!-- start doc -->//s;
112 1 $html_str =~ s/<!-- end doc -->.*//s;
113  
114 1 $log->debug( "pod_to_html after: $html_str" );
115 1 return $html_str;
116 }
117  
118  
119 =head2 pod_to_text
120  
121 Convert POD string into text
122  
123 =cut
124  
125 sub pod_to_text {
126 0 ▶ my $pod_str = shift;
Subroutine pod_to_text: not called CC=1 SCAR=6.9
Pod documented
127 0 $log->debug( "Entering " . __PACKAGE__ . "::pod_to_text" );
128  
129 0 my $p = Pod::Simple::Text->new;
130 0 $p->output_string(\my $text_str);
131 0 $p->parse_string_document($pod_str);
132 0 return $text_str;
133 }
134  
135 22 1;
« blib/lib/Web/MREST/WebServicesIntro.pm ↑ Summary blib/lib/Web/MREST/Test/503.pm »