Test/Without/GD.pm

filter: Statementstmt 23.8% 16 / 67 Branchbran 0.0% 0 / 16 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 26.3% 5 / 19 Podpod 100% 5 / 5 totaltotal 24.3% 26 / 107 CC 11 SCAR 16.4
CC
11
Cov
19%
import
13.3
unimport
6.0
without_jpeg
6.0
CRAP 5.2
« Module/Util/Masked.pm ↑ Summary
1 # Copyright 2011, 2012, 2015, 2017, 2024 Kevin Ryde
2  
3 # This file is part of Test-VariousBits.
4 #
5 # Test-VariousBits is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as published
7 # by the Free Software Foundation; either version 3, or (at your option) any
8 # later version.
9 #
10 # Test-VariousBits is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
13 # Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License along
16 # with Test-VariousBits. If not, see <http://www.gnu.org/licenses/>.
17  
18  
19 package Test::Without::GD;
20 2 ▶use 5.004; # for ->can()
Subroutine BEGIN: called CC=1 SCAR=0.0
21 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23 2 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 2 $VERSION = 8;
25  
26 # uncomment this to run the ### lines
27 #use Smart::Comments;
28  
29  
30 0 ▶sub _croak {
Subroutine _croak: not called CC=1 SCAR=6.9
31 0 require Carp;
32 0 Carp::croak(@_);
33 }
34  
35 2 ▶sub import {
Subroutine import: called CC=4 SCAR=25.8
36 2 my $class = shift;
37 2 foreach (@_) {
38 0 ▶ if (/^-/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/^-/) 0 0 0
39 0 my $method = 'without_' . substr($_,1);
40 0 ▶ if ($class->can($method)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($class->can($method)) 0 0 0
41 0 $class->$method();
42 0 next;
43 }
44 }
45 0 _croak 'Unrecognised without option: ',$_;
46 }
47 }
48  
49 2 my %replaced;
50  
51 0 ▶sub unimport {
Subroutine unimport: not called CC=2 SCAR=17.9
52 0 foreach my $name (keys %replaced) {
53 0 local $^W = 0;
54 0 *$name = delete $replaced{$name};
55 }
56 }
57  
58 #------------------------------------------------------------------------------
59 0 ▶sub without_jpeg {
Subroutine without_jpeg: not called CC=2 SCAR=17.9
Pod documented
60 0 _without_func('GD::Image::_newFromJpeg');
61 0 _without_func('GD::Image::newFromJpegData');
62 0 _without_func('GD::Image::jpeg');
63 0 ▶ if (my $coderef = GD::Image->can('jpeg')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $coderef = "GD::Image"->can("jpeg")) 0 0 0
64 0 die "Oops, GD::Image->can('jpeg') still true: $coderef";
65 }
66 }
67  
68 #------------------------------------------------------------------------------
69 0 ▶sub without_png {
Subroutine without_png: not called CC=2 SCAR=17.9
Pod documented
70 0 _without_func('GD::Image::_newFromPng');
71 0 _without_func('GD::Image::newFromPngData');
72 0 _without_func('GD::Image::png');
73 0 ▶ if (my $coderef = GD::Image->can('png')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $coderef = "GD::Image"->can("png")) 0 0 0
74 0 die "Oops, GD::Image->can('png') still true: $coderef";
75 }
76 }
77  
78 #------------------------------------------------------------------------------
79 0 ▶sub without_gif {
Subroutine without_gif: not called CC=2 SCAR=17.9
Pod documented
80 0 _without_func('GD::Image::_newFromGif');
81 0 _without_func('GD::Image::newFromGifData');
82 0 _without_func('GD::Image::gif');
83 0 ▶ if (my $coderef = GD::Image->can('gif')) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $coderef = "GD::Image"->can("gif")) 0 0 0
84 0 die "Oops, GD::Image->can('gif') still true: $coderef";
85 }
86 }
87  
88 #------------------------------------------------------------------------------
89  
90 0 ▶sub without_gifanim {
Subroutine without_gifanim: not called CC=2 SCAR=17.9
Pod documented
91 0 _change_func('GD::Image::gifanimbegin', \&_Test_Without_GD__gifanimbegin);
92 0 _change_func('GD::Image::gifanimadd', \&_Test_Without_GD__gifanimadd);
93 0 _change_func('GD::Image::gifanimend', \&_Test_Without_GD__gifanimend);
94 0 ▶ if (eval { GD::Image->gifanim; 1 }) {
Branch: 1 branch
BranchTrueFalseTotal
if (eval { do { "GD::Image"->gifanim; 1 } }) 0 0 0
95 0 die "Oops, GD::Image->gifanim() still works";
96 }
97 }
98 # prototypes here per GD.xs, but presumably have no effect since they're
99 # supposed to be called as methods
100 0 ▶sub _Test_Without_GD__gifanimbegin ($$$) {
Subroutine _Test_Without_GD__gifanimbegin: not called CC=1 SCAR=6.9
101 # die per gdgifanimbegin() in GD.xs when HAVE_ANIMGIF false
102 0 die "libgd 2.0.33 or higher required for animated GIF support";
103 }
104 0 ▶sub _Test_Without_GD__gifanimadd ($$$$$$$) {
Subroutine _Test_Without_GD__gifanimadd: not called CC=1 SCAR=6.9
105 # die per gdgifanimadd() in GD.xs when HAVE_ANIMGIF false
106 0 die "libgd 2.0.33 or higher required for animated GIF support";
107 }
108 0 ▶sub _Test_Without_GD__gifanimend ($) {
Subroutine _Test_Without_GD__gifanimend: not called CC=1 SCAR=6.9
109 # die per gdgifanimbegin() in GD.xs when HAVE_ANIMGIF false
110 0 die "libgd 2.0.33 or higher required for animated GIF support";
111 }
112  
113 #------------------------------------------------------------------------------
114  
115 0 ▶sub without_xpm {
Subroutine without_xpm: not called CC=1 SCAR=6.9
Pod documented
116 0 _change_func('GD::Image::newFromXpm', \&_Test_Without_GD__newFromXpm);
117 }
118 # prototype here per GD.xs, but presumably has no effect since it's supposed
119 # to be called as a method
120 0 ▶sub _Test_Without_GD__newFromXpm ($$) {
Subroutine _Test_Without_GD__newFromXpm: not called CC=1 SCAR=6.9
121 ### _Test_Without_GD__newFromXpm() ...
122 # empty return and $@ per gdnewFromXpm() in GD.xs when HAVE_XPM false
123 0 $@ = "libgd was not built with xpm support\n";
124 0 return;
125 }
126  
127 #------------------------------------------------------------------------------
128  
129 0 ▶sub _without_func {
Subroutine _without_func: not called CC=2 SCAR=17.9
130 0 my ($name) = @_;
131 0 require GD;
132 0 ▶ unless ($replaced{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($replaced{$name}) 0 0 0
133 ### remove: $name
134 0 $replaced{$name} = \&$name;
135 0 require Sub::Delete;
136 0 Sub::Delete::delete_sub($name);
137 }
138 }
139 0 ▶sub _change_func {
Subroutine _change_func: not called CC=2 SCAR=12.6
140 0 my ($name, $new_coderef) = @_;
141 ### _change_func(): $name
142 ### $new_coderef
143 ### name prototype: prototype $name
144 ### new prototype : prototype $new_coderef
145  
146 0 require GD;
147 0 ▶ unless ($replaced{$name}) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($replaced{$name}) 0 0 0
148 0 $replaced{$name} = \&$name;
149 2 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
150 0 ▶ local $SIG{'__WARN__'} = sub {};
Subroutine __ANON__: not called CC=1 SCAR=6.9
151 0 *$name = $new_coderef;
152 }
153 }
154  
155 2 1;
156 __END__
« Module/Util/Masked.pm ↑ Summary