Convert.pm

filter: Statementstmt 38.1% 16 / 42 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 62.5% 5 / 8 Podpod 100% 3 / 3 totaltotal 30.3% 24 / 79 CC 11 SCAR 41.3
CC
11
Cov
25%
said
110.0
init
6.0
help
2.0
CRAP 62.2
« Funcs.pm ↑ Summary Translate.pm »
1 package Bot::BasicBot::Pluggable::Module::Convert;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Bot::BasicBot::Pluggable::Module;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use base qw(Bot::BasicBot::Pluggable::Module);
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Math::Units;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use Finance::Currency::Convert::XE;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10  
11 0 ▶sub init {
Subroutine init: not called CC=2 SCAR=17.9
Pod documented
12 0 my $self = shift;
13 0 $self->{converter} = Finance::Currency::Convert::XE->new();
14 0 ▶ $self->set("user_scientific_limit", 999999999) unless $self->get("user_scientific_limit");
Branch: 1 branch
BranchTrueFalseTotal
unless $self->get("user_scientific_limit") 0 0 0
15 0 $self->unset("user_scientific_limit");
16  
17 }
18  
19 0 ▶sub said {
Subroutine said: not called CC=10 SCAR=47.0
Pod documented
20 0 my ($self, $mess, $pri) = @_;
21  
22 0 my $body = $mess->{body};
23 0 my $who = $mess->{who};
24  
25 0 ▶ return unless ($pri == 2);
Branch: 1 branch
BranchTrueFalseTotal
unless $pri == 2 0 0 0
26  
27 0 ▶ return unless $body =~ /^\s*(?:ex)?(?:change|convert)\s+([\d\.\,]+)\s*(\S+)\s+(?:into|to|for)\s+(\S+)/i;
Branch: 1 branch
BranchTrueFalseTotal
unless $body =~ /^\s*(?:ex)?(?:change|convert)\s+([\d\.\,]+)\s*(\S+)\s+(?:into|to|for)\s+(\S+)/i 0 0 0
28 0 my ($amount, $from, $to) = ($1,$2,$3);
29  
30  
31 # first try and convert units
32  
33 0 my $val = eval { Math::Units::convert($amount, $from, $to) };
34 0 ▶ goto CURRENCY if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
35  
36 0 my $limit = $self->get("user_scientific_limit");
37  
38 0 ▶ if (defined $limit && $limit < $val) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $limit and $limit < $val) 0 0 0
Condition0%0/3
defined $limit and $limit < $val
!ll&&!rl&&r
000
MC/DC0%0/2
defined $limit and $limit < $val
defined $limit $limit < $val
Truth table0%0/3
A and B
A= defined $limitB= $limit < $val
ABresult
0X0
100
111
39 0 $val = sprintf "%e", $val;
40 }
41  
42  
43 0 ▶ return "Dunno about that" unless defined $val && $val !~ m!^\s*$!;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val and not $val =~ /^\s*$/ 0 0 0
Condition0%0/3
defined $val and not $val =~ /^\s*$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $val and not $val =~ /^\s*$/
defined $val not $val =~ /^\s*$/
Truth table0%0/3
A and not(B)
A= defined $valB= not $val =~ /^\s*$/
ABresult
0X0
100
111
44  
45 0 return "$amount $from is $val $to";
46 CURRENCY:
47  
48 0 my $obj = $self->{converter};
49 0 ▶ return "Currency conversion not working" unless $obj;
Branch: 1 branch
BranchTrueFalseTotal
unless $obj 0 0 0
50
51 0 $from = uc($from);
52 0 $to = uc($to);
53 0 $val = $obj->convert(
54 'source' => $from,
55 'target' => $to,
56 'value' => $amount,
57 'format' => 'number'
58 );
59  
60 0 ▶ return "Couldn't out what to do with with the units $from and $to" unless defined $val;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $val 0 0 0
61 0 return "$amount $from is $val $to";
62 }
63  
64 0 ▶sub help {
Subroutine help: not called CC=1 SCAR=6.9
Pod documented
65 0 return "Commands: 'convert <quantity> <unit> to <other unit>' or 'exchange <quantity> <currency> to <other currency>'";
66 }
67  
68 1 1;
69  
70  
71 __END__
« Funcs.pm ↑ Summary Translate.pm »