« blib/lib/Bot/Cobalt/Plugin/Games/Dice.pm
↑ Summary
blib/lib/Bot/Cobalt/Plugin/RDB/AsyncSearch/Worker.pm »
| 1 | package Bot::Cobalt::Plugin::Extras::TempConv; | ||||||||||||||||||||||||||||||||
| 2 | 1 | $Bot::Cobalt::Plugin::Extras::TempConv::VERSION = '0.021003'; | |||||||||||||||||||||||||||||||
| 3 | ## RECEIVES AND EATS: | ||||||||||||||||||||||||||||||||
| 4 | ## _public_cmd_tempconv ( !tempconv ) | ||||||||||||||||||||||||||||||||
| 5 | ## _public_cmd_temp ( !temp ) | ||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use strictures 2; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Object::Pluggable::Constants qw/ :ALL /; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Bot::Cobalt::Utils qw/ color /; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use constant MAX_TEMP => 100_000_000_000; | ||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | sub new { bless [], shift } | ||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub Cobalt_register { | ||||||||||||||||||||||||||||||
|
Subroutine
Cobalt_register: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 17 | 0 | my ($self, $core) = splice @_, 0, 2; | |||||||||||||||||||||||||||||||
| 18 | 0 | $core->plugin_register( $self, 'SERVER', | |||||||||||||||||||||||||||||||
| 19 | qw/ | ||||||||||||||||||||||||||||||||
| 20 | public_cmd_temp | ||||||||||||||||||||||||||||||||
| 21 | public_cmd_tempconv | ||||||||||||||||||||||||||||||||
| 22 | /, | ||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||
| 25 | 0 | $core->log->info("Registered, cmds: temp tempconv"); | |||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||
| 27 | 0 | return PLUGIN_EAT_NONE | |||||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub Cobalt_unregister { | ||||||||||||||||||||||||||||||
|
Subroutine
Cobalt_unregister: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 31 | 0 | my ($self, $core) = splice @_, 0, 2; | |||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||
| 33 | 0 | $core->log->info("Unregistering"); | |||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||
| 35 | 0 | return PLUGIN_EAT_NONE | |||||||||||||||||||||||||||||||
| 36 | } | ||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||
| 38 | ## !temp(conv): | ||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | sub Bot_public_cmd_tempconv { Bot_public_cmd_temp(@_) } | ||||||||||||||||||||||||||||||
|
Subroutine
Bot_public_cmd_tempconv: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 40 | 0 | ▶ | sub Bot_public_cmd_temp { | ||||||||||||||||||||||||||||||
|
Subroutine
Bot_public_cmd_temp: not called CC=14 SCAR=53.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||
| 41 | 0 | my ($self, $core) = splice @_, 0, 2; | |||||||||||||||||||||||||||||||
| 42 | 0 | my $msg = ${ $_[0] }; | |||||||||||||||||||||||||||||||
| 43 | 0 | my $context = $msg->context; | |||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||
| 45 | 0 | ▶ | my $str = $msg->message_array->[0] || ''; | ||||||||||||||||||||||||||||||
|
Condition0%0/2
$msg->message_array->[0] || ''
MC/DC0%0/1
$msg->message_array->[0] || ''
$msg->message_array->[0]
Truth table0%0/2
A
A= $msg->message_array->[0]
| |||||||||||||||||||||||||||||||||
| 46 | 0 | my ($temp, $type) = $str =~ /(-?\d+\.?\d*)?(\w)?/; | |||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | $temp = 0 unless $temp; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | $temp = MAX_TEMP if $temp > MAX_TEMP; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | $type = 'F' unless $type and grep { $_ eq uc($type) } qw/F C K/; | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$type and grep {$_ eq uc $type;} "F", "C", "K"
MC/DC0%0/2
$type and grep {$_ eq uc $type;} "F", "C", "K"
$type
grep {$_ eq uc $type;} "F", "C", "K"
Truth table0%0/3
A and B
A= $typeB= grep {$_ eq uc $type;} "F", "C", "K"
| |||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||
| 52 | 0 | my ($f, $k, $c); | |||||||||||||||||||||||||||||||
| 53 | 0 | for my $upper (uc $type) { | |||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | ( ($f, $k, $c) = ( $temp, _f2k($temp), _f2c($temp) ) and last ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$upper eq 'F' && ((() = ($temp, _f2k($temp), _f2c($temp))) && (last))
() = ($temp, _f2k($temp), _f2c($temp)) and last
MC/DC0%0/2
$upper eq 'F' && ((() = ($temp, _f2k($temp), _f2c($temp))) && (last))
$upper eq 'F'
() = ($temp, _f2k($temp), _f2c($temp))
Truth table0%0/3
A && B
A= $upper eq 'F'B= () = ($temp, _f2k($temp), _f2c($temp))
| |||||||||||||||||||||||||||||||||
| 55 | if $upper eq 'F'; | ||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | ( ($f, $k, $c) = ( _c2f($temp), _c2k($temp), $temp ) and last ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$upper eq 'C' && ((() = (_c2f($temp), _c2k($temp), $temp)) && (last))
() = (_c2f($temp), _c2k($temp), $temp) and last
MC/DC0%0/2
$upper eq 'C' && ((() = (_c2f($temp), _c2k($temp), $temp)) && (last))
$upper eq 'C'
() = (_c2f($temp), _c2k($temp), $temp)
Truth table0%0/3
A && B
A= $upper eq 'C'B= () = (_c2f($temp), _c2k($temp), $temp)
| |||||||||||||||||||||||||||||||||
| 58 | if $upper eq 'C'; | ||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | ( ($f, $k, $c) = ( _k2f($temp), $temp, _k2c($temp) ) and last ) | ||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/5
$upper eq 'K' && ((() = (_k2f($temp), $temp, _k2c($temp))) && (last))
() = (_k2f($temp), $temp, _k2c($temp)) and last
MC/DC0%0/2
$upper eq 'K' && ((() = (_k2f($temp), $temp, _k2c($temp))) && (last))
$upper eq 'K'
() = (_k2f($temp), $temp, _k2c($temp))
Truth table0%0/3
A && B
A= $upper eq 'K'B= () = (_k2f($temp), $temp, _k2c($temp))
| |||||||||||||||||||||||||||||||||
| 61 | if $upper eq 'K'; | ||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||
| 64 | 0 | $_ = sprintf("%.2f", $_) for ($f, $k, $c); | |||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||
| 66 | 0 | my $resp = color( 'bold', "(${f}F)" ) | |||||||||||||||||||||||||||||||
| 67 | . " == " . | ||||||||||||||||||||||||||||||||
| 68 | color( 'bold', "(${c}C)" ) | ||||||||||||||||||||||||||||||||
| 69 | . " == " . | ||||||||||||||||||||||||||||||||
| 70 | color( 'bold', "(${k}K)" ); | ||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||
| 72 | 0 | my $channel = $msg->channel; | |||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||
| 74 | 0 | $core->send_event( 'message', $context, $channel, $resp ); | |||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||
| 76 | 0 | return PLUGIN_EAT_ALL | |||||||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||
| 79 | ## Conversion functions: | ||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub _f2c { (shift(@_) - 32 ) * (5/9) } | ||||||||||||||||||||||||||||||
|
Subroutine
_f2c: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub _f2k { (shift(@_) + 459.67) * (5/9) } | ||||||||||||||||||||||||||||||
|
Subroutine
_f2k: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | sub _c2f { shift(@_) * (9/5) + 32 } | ||||||||||||||||||||||||||||||
|
Subroutine
_c2f: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub _c2k { shift(@_) + 273.15 } | ||||||||||||||||||||||||||||||
|
Subroutine
_c2k: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub _k2f { shift(@_) * (9/5) - 459.67 } | ||||||||||||||||||||||||||||||
|
Subroutine
_k2f: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | sub _k2c { shift(@_) - 273.15 } | ||||||||||||||||||||||||||||||
|
Subroutine
_k2c: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||
| 89 | 1 | 1; | |||||||||||||||||||||||||||||||
| 90 | __END__ | ||||||||||||||||||||||||||||||||