Chit/Command/temperature.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 62 CC 5 SCAR 20.4
CC
5
Cov
0%
validate_args
20.0
execute
6.0
abstract
2.0
CRAP 7.7
1 use v5.20;
2 use strict;
3 use warnings;
4 use experimental qw( signatures lexical_subs postderef );
5  
6 package App::Chit::Command::temperature;
7  
8 use App::Chit -command;
9  
10 use App::Chit::Util ();
11  
12 our $AUTHORITY = 'cpan:TOBYINK';
13 our $VERSION = '0.001001';
14  
15 sub abstract {
16 return "Show or set the temperature for this chat."
17 }
18  
19 sub opt_spec {
20 return (
21 [ "set=f", "set temperature (decimal number from 0.0 to 2.0)" ],
22 );
23 }
24  
25 sub validate_args ( $self, $opt, $args ) {
26 if ( exists $opt->{set} ) {
27 $self->usage_error( "too hot" ) if $opt->{set} > 2;
28 $self->usage_error( "too cold" ) if $opt->{set} < 0;
29 }
30 }
31  
32 sub execute ( $self, $opt, $args ) {
33 my $dir = App::Chit::Util::find_chit_dir()
34 or $self->usage_error("need to initialize chit first");
35 my $chit = App::Chit::Util::load_chit( $dir );
36
37 if ( $opt->{set} ) {
38 say "Previous temperature: ", sprintf( '%.03f', $chit->{temperature} );
39 say "Setting temperature to: ", $opt->{set};
40 $chit->{temperature} = $opt->{set};
41 }
42 else {
43 say sprintf( '%.03f', $chit->{temperature} );
44 }
45
46 App::Chit::Util::save_chit( $dir, $chit );
47 }
48  
49 1;