line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#============================================================= -*-Perl-*- |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Template::Plugin::Math |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# DESCRIPTION |
6
|
|
|
|
|
|
|
# Plugin implementing numerous mathematical functions. |
7
|
|
|
|
|
|
|
# |
8
|
|
|
|
|
|
|
# AUTHORS |
9
|
|
|
|
|
|
|
# Andy Wardley |
10
|
|
|
|
|
|
|
# |
11
|
|
|
|
|
|
|
# COPYRIGHT |
12
|
|
|
|
|
|
|
# Copyright (C) 2002-2007 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
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
44
|
|
22
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
23
|
1
|
|
|
1
|
|
4
|
use base 'Template::Plugin'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
474
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
our $VERSION = 1.16; |
26
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub new { |
39
|
10
|
|
|
10
|
1
|
13
|
my ($class, $context, $config) = @_; |
40
|
10
|
|
50
|
|
|
37
|
$config ||= { }; |
41
|
|
|
|
|
|
|
|
42
|
10
|
|
|
|
|
56
|
bless { |
43
|
|
|
|
|
|
|
%$config, |
44
|
|
|
|
|
|
|
}, $class; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
1
|
|
|
1
|
1
|
2
|
sub abs { shift; CORE::abs($_[0]); } |
|
1
|
|
|
|
|
5
|
|
48
|
1
|
|
|
1
|
1
|
2
|
sub atan2 { shift; CORE::atan2($_[0], $_[1]); } # prototyped (ugg) |
|
1
|
|
|
|
|
20
|
|
49
|
1
|
|
|
1
|
1
|
2
|
sub cos { shift; CORE::cos($_[0]); } |
|
1
|
|
|
|
|
30
|
|
50
|
1
|
|
|
1
|
1
|
2
|
sub exp { shift; CORE::exp($_[0]); } |
|
1
|
|
|
|
|
18
|
|
51
|
1
|
|
|
1
|
1
|
1
|
sub hex { shift; CORE::hex($_[0]); } |
|
1
|
|
|
|
|
5
|
|
52
|
1
|
|
|
1
|
1
|
4
|
sub int { shift; CORE::int($_[0]); } |
|
1
|
|
|
|
|
5
|
|
53
|
1
|
|
|
1
|
1
|
2
|
sub log { shift; CORE::log($_[0]); } |
|
1
|
|
|
|
|
15
|
|
54
|
1
|
|
|
1
|
1
|
2
|
sub oct { shift; CORE::oct($_[0]); } |
|
1
|
|
|
|
|
5
|
|
55
|
0
|
|
|
0
|
1
|
0
|
sub rand { shift; CORE::rand($_[0]); } |
|
0
|
|
|
|
|
0
|
|
56
|
1
|
|
|
1
|
1
|
2
|
sub sin { shift; CORE::sin($_[0]); } |
|
1
|
|
|
|
|
14
|
|
57
|
1
|
|
|
1
|
1
|
2
|
sub sqrt { shift; CORE::sqrt($_[0]); } |
|
1
|
|
|
|
|
25
|
|
58
|
0
|
|
|
0
|
1
|
|
sub srand { shift; CORE::srand($_[0]); } |
|
0
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Use the Math::TrulyRandom module |
61
|
|
|
|
|
|
|
# XXX This is *sloooooooowwwwwwww* |
62
|
|
|
|
|
|
|
sub truly_random { |
63
|
0
|
0
|
|
0
|
0
|
|
eval { require Math::TrulyRandom; } |
|
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
|
|
|
|
|
|
|
eval { |
70
|
|
|
|
|
|
|
require Math::Trig; |
71
|
1
|
|
|
1
|
|
6
|
no strict qw(refs); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
124
|
|
72
|
|
|
|
|
|
|
for my $trig_func (@Math::Trig::EXPORT) { |
73
|
|
|
|
|
|
|
my $sub = Math::Trig->can($trig_func); |
74
|
0
|
|
|
0
|
|
|
*{$trig_func} = sub { shift; &$sub(@_) }; |
|
0
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
}; |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# To catch errors from a missing Math::Trig |
79
|
0
|
|
|
0
|
|
|
sub AUTOLOAD { return; } |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
__END__ |