blib/lib/Markdown/Pod/Embed/Util.pm

filter: Statementstmt 79.2% 42 / 53 Branchbran 38.8% 7 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 60.0% 9 / 15 Podpod 0.0% 0 / 9 totaltotal 61.0% 58 / 95 CC 10 SCAR 11.5
CC
10
Cov
69%
msg
6.0
verbose
6.0
slurp
4.2
CRAP 3.1
« blib/lib/Markdown/Pod/Embed.pm ↑ Summary blib/lib/Markdown/Pod/Embed/Constant.pm »
1 #
2 # This file is part of Markdown::Pod::Embed.
3 #
4 # This software is copyright (c) 2026 by Andrew Speer <andrew.speer@isolutions.com.au>.
5 #
6 # This is free software; you can redistribute it and/or modify it under
7 # the same terms as the Perl 5 programming language system itself.
8 #
9 # Full license text is available at:
10 #
11 # <http://dev.perl.org/licenses/>
12 #
13 package Markdown::Pod::Embed::Util;
14  
15  
16 # Compiler pragma and package variables
17 #
18 8 ▶use strict qw(vars);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 8 ▶use vars qw($VERSION @ISA @EXPORT $QUIET $VERBOSE $DEBUG);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22  
23 # External packages
24 #
25 8 ▶use Carp qw(croak);
Subroutine BEGIN: called CC=1 SCAR=0.0
26 8 ▶use Data::Dumper qw(Dumper);
Subroutine BEGIN: called CC=1 SCAR=0.0
27 8 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29  
30 # Version and exports
31 #
32 8 $VERSION='1.012';
33 8 @ISA=qw(Exporter);
34 8 @EXPORT=qw(err msg debug verbose slurp blurp Dumper quiet_enable
35 verbose_enable debug_enable);
36  
37  
38 # Package state
39 #
40 8 $QUIET=0;
41 8 $VERBOSE=0;
42 8 $DEBUG=0;
43  
44  
45 # Done
46 #
47 8 1;
48  
49  
50 #===================================================================================================
51  
52 0 ▶sub err {
Subroutine err: not called CC=1 SCAR=6.9
Pod undocumented
53  
54 0 croak(sprintf(shift(), @_));
55  
56 }
57  
58  
59 0 ▶sub msg {
Subroutine msg: not called CC=2 SCAR=17.9
Pod undocumented
60  
61 0 ▶ print STDERR sprintf(shift(), @_), "\n" unless $QUIET;
Branch: 1 branch
BranchTrueFalseTotal
unless $Markdown::Pod::Embed::Util::QUIET 0 0 0
62 0 return undef;
63  
64 }
65  
66  
67 94 ▶sub debug {
Subroutine debug: called CC=2 SCAR=7.2
Pod undocumented
68  
69 94 ▶ msg(@_) if $DEBUG;
Branch: 1 branch
BranchTrueFalseTotal
if $Markdown::Pod::Embed::Util::DEBUG 0 94 94
70 94 return undef;
71  
72 }
73  
74  
75 0 ▶sub verbose {
Subroutine verbose: not called CC=2 SCAR=17.9
Pod undocumented
76  
77 0 ▶ msg(@_) if $VERBOSE;
Branch: 1 branch
BranchTrueFalseTotal
if $Markdown::Pod::Embed::Util::VERBOSE 0 0 0
78 0 return undef;
79  
80 }
81  
82  
83 0 ▶sub quiet_enable {
Subroutine quiet_enable: not called CC=1 SCAR=6.9
Pod undocumented
84  
85 0 $QUIET=shift();
86 0 return $QUIET;
87  
88 }
89  
90  
91 0 ▶sub verbose_enable {
Subroutine verbose_enable: not called CC=1 SCAR=6.9
Pod undocumented
92  
93 0 $VERBOSE=shift();
94 0 return $VERBOSE;
95  
96 }
97  
98  
99 0 ▶sub debug_enable {
Subroutine debug_enable: not called CC=1 SCAR=6.9
Pod undocumented
100  
101 0 $DEBUG=shift();
102 0 return $DEBUG;
103  
104 }
105  
106  
107 17 ▶sub slurp {
Subroutine slurp: called CC=4 SCAR=14.3
Pod undocumented
108  
109  
110 # Read the complete file without changing line endings
111 #
112 17 my ($fn)=@_;
113 17 ▶ open(my $input_fh, '<', $fn) ||
Branch: 1 branch
BranchTrueFalseTotal
open my $input_fh, "<", $fn or err("unable to read %s: %s", $fn, $!) 17 0 17
114 err('unable to read %s: %s', $fn, $!);
115 17 binmode($input_fh);
116 17 local $/;
117 17 my $text=<$input_fh>;
118 17 ▶ close($input_fh) ||
Branch: 1 branch
BranchTrueFalseTotal
close $input_fh or err("unable to close %s: %s", $fn, $!) 17 0 17
119 err('unable to close %s: %s', $fn, $!);
120 17 ▶ return defined($text) ? $text : '';
Branch: 1 branch
BranchTrueFalseTotal
defined $text ? : 17 0 17
121  
122 }
123  
124  
125 7 ▶sub blurp {
Subroutine blurp: called CC=4 SCAR=14.2
Pod undocumented
126  
127  
128 # Write the complete file without changing line endings
129 #
130 7 my ($fn, $text)=@_;
131 7 ▶ open(my $output_fh, '>', $fn) ||
Branch: 1 branch
BranchTrueFalseTotal
open my $output_fh, ">", $fn or err("unable to write %s: %s", $fn, $!) 7 0 7
132 err('unable to write %s: %s', $fn, $!);
133 7 binmode($output_fh);
134 7 my $write_ok=print {$output_fh} $text;
135 7 ▶ $write_ok || err('unable to write %s: %s', $fn, $!);
Branch: 1 branch
BranchTrueFalseTotal
$write_ok or err("unable to write %s: %s", $fn, $!) 7 0 7
136 7 ▶ close($output_fh) ||
Branch: 1 branch
BranchTrueFalseTotal
close $output_fh or err("unable to close %s: %s", $fn, $!) 7 0 7
137 err('unable to close %s: %s', $fn, $!);
138 7 return 1;
139  
140 }
141 __END__
« blib/lib/Markdown/Pod/Embed.pm ↑ Summary blib/lib/Markdown/Pod/Embed/Constant.pm »