| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 0 | ▶ | return unless $body =~ /^\s*(?:ex)?(?:change|convert)\s+([\d\.\,]+)\s*(\S+)\s+(?:into|to|for)\s+(\S+)/i; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | my $limit = $self->get("user_scientific_limit"); | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | if (defined $limit && $limit < $val) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $limit and $limit < $val
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
| |||||||||||||||||||||||||||||
| 39 | 0 | $val = sprintf "%e", $val; | |||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 0 | ▶ | return "Dunno about that" unless defined $val && $val !~ m!^\s*$!; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $val and not $val =~ /^\s*$/
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*$/
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||