lib/Template/Plugin/Math.pm

filter: Statementstmt 88.8% 48 / 54 Branchbran 66.6% 4 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 85.0% 17 / 20 Podpod 92.8% 13 / 14 totaltotal 85.5% 83 / 97 CC 5 SCAR 5.4
CC
5
Cov
85%
truly_random
6.0
new
2.0
rand
2.0
CRAP 1.7
« lib/Template/Plugin/Assert.pm ↑ Summary lib/Template/Plugin/Format.pm »
1 #============================================================= -*-Perl-*-
2 #
3 # Template::Plugin::Math
4 #
5 # DESCRIPTION
6 # Plugin implementing numerous mathematical functions.
7 #
8 # AUTHORS
9 # Andy Wardley <abw@wardley.org>
10 #
11 # COPYRIGHT
12 # Copyright (C) 2002-2022 Andy Wardley. All Rights Reserved.
13 #
14 # This module is free software; you can redistribute it and/or
15 # modify it under the same terms as Perl itself.
16 #
17 #============================================================================
18  
19 package Template::Plugin::Math;
20  
21 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 2 ▶use base 'Template::Plugin';
Subroutine BEGIN: called CC=1 SCAR=0.0
24  
25 2 our $VERSION = '3.106';
26 2 our $AUTOLOAD;
27  
28  
29 #------------------------------------------------------------------------
30 # new($context, \%config)
31 #
32 # This constructor method creates a simple, empty object to act as a
33 # receiver for future object calls. No doubt there are many interesting
34 # configuration options that might be passed, but I'll leave that for
35 # someone more knowledgable in these areas to contribute...
36 #------------------------------------------------------------------------
37  
38 11 ▶sub new {
Subroutine new: called CC=2 SCAR=7.1
Pod documented
39 11 my ($class, $context, $config) = @_;
40 11 ▶ $config ||= { };
Condition50%1/2
$config ||= {}
l!l
011
MC/DC0%0/1
$config ||= {}
$config
Truth table50%1/2
A
A= $config
Aresult
11
00
41  
42 11 bless {
43 %$config,
44 }, $class;
45 }
46  
47 1 ▶sub abs { shift; CORE::abs($_[0]); }
Subroutine abs: called CC=1 SCAR=0.0
Pod documented
48 1 ▶sub atan2 { shift; CORE::atan2($_[0], $_[1]); } # prototyped (ugg)
Subroutine atan2: called CC=1 SCAR=0.0
Pod documented
49 1 ▶sub cos { shift; CORE::cos($_[0]); }
Subroutine cos: called CC=1 SCAR=0.0
Pod documented
50 1 ▶sub exp { shift; CORE::exp($_[0]); }
Subroutine exp: called CC=1 SCAR=0.0
Pod documented
51 1 ▶sub hex { shift; CORE::hex($_[0]); }
Subroutine hex: called CC=1 SCAR=0.0
Pod documented
52 1 ▶sub int { shift; CORE::int($_[0]); }
Subroutine int: called CC=1 SCAR=0.0
Pod documented
53 1 ▶sub log { shift; CORE::log($_[0]); }
Subroutine log: called CC=1 SCAR=0.0
Pod documented
54 1 ▶sub oct { shift; CORE::oct($_[0]); }
Subroutine oct: called CC=1 SCAR=0.0
Pod documented
55 2 ▶sub rand { shift; @_ ? CORE::rand($_[0]) : CORE::rand(); }
Subroutine rand: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 1 1 2
56 1 ▶sub sin { shift; CORE::sin($_[0]); }
Subroutine sin: called CC=1 SCAR=0.0
Pod documented
57 1 ▶sub sqrt { shift; CORE::sqrt($_[0]); }
Subroutine sqrt: called CC=1 SCAR=0.0
Pod documented
58 2 ▶sub srand { shift; @_ ? CORE::srand($_[0]) : CORE::srand(); }
Subroutine srand: called CC=2 SCAR=6.9
Pod documented
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 1 1 2
59  
60 # Use the Math::TrulyRandom module
61 # XXX This is *sloooooooowwwwwwww*
62 0 ▶sub truly_random {
Subroutine truly_random: not called CC=2 SCAR=17.9
Pod undocumented
63 0 ▶ eval { require Math::TrulyRandom; }
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Math::TrulyRandom } } or die "Template::Exception"->new("plugin", "Can't load Math::TrulyRandom") 0 0 0
64 or die(Template::Exception->new("plugin",
65 "Can't load Math::TrulyRandom"));
66 0 return Math::TrulyRandom::truly_random_value();
67 }
68  
69 2 eval {
70 2 require Math::Trig;
71 2 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
72 2 for my $trig_func (@Math::Trig::EXPORT) {
73 78 my $sub = Math::Trig->can($trig_func);
74 0 ▶ *{$trig_func} = sub { shift; &$sub(@_) };
Subroutine __ANON__: not called CC=1 SCAR=1.2
75 }
76 };
77  
78 # To catch errors from a missing Math::Trig
79 0 ▶sub AUTOLOAD { return; }
Subroutine AUTOLOAD: not called CC=1 SCAR=6.9
80  
81 2 1;
82  
83 __END__
« lib/Template/Plugin/Assert.pm ↑ Summary lib/Template/Plugin/Format.pm »