File Coverage

blib/lib/App/RemoteGnokii.pm
Criterion Covered Total %
statement 21 42 50.0
branch 0 8 0.0
condition 0 2 0.0
subroutine 7 12 58.3
pod 0 4 0.0
total 28 68 41.1


line stmt bran cond sub pod time code
1             package App::RemoteGnokii;
2              
3 1     1   25395 use 5.014000;
  1         7  
  1         46  
4 1     1   6 use strict;
  1         1  
  1         58  
5 1     1   6 use warnings;
  1         6  
  1         60  
6             our $VERSION = '0.001';
7              
8 1     1   688 use Config::Any;
  1         11460  
  1         48  
9 1     1   775 use File::Copy qw/move/;
  1         4303  
  1         61  
10 1     1   636 use File::Temp qw/tempfile/;
  1         15257  
  1         61  
11 1     1   435 use Plack::Request;
  1         33982  
  1         321  
12              
13             my $cfg;
14              
15             sub cfg ($){ ## no critic (ProhibitSubroutinePrototypes)
16 0 0   0 0   unless ($cfg) {
17 0   0       $cfg = Config::Any->load_stems({stems => [$ENV{RGCONFIG} // '/etc/rg'], use_ext => 1, flatten_to_hash => 1});
18 0           my @cfg = values %$cfg;
19 0           $cfg = $cfg[0];
20             }
21              
22 0           $cfg->{$_[0]}
23             }
24              
25             sub sendsms {
26 0     0 0   my ($number, $text) = @_;
27 0           my ($fh, $file) = tempfile 'smsXXXX', TMPDIR => 1;
28 0 0         print $fh "$number\n$text" or warn "print: $!"; ## no critic (RequireCarping)
29 0 0         close $fh or warn "close: $!"; ## no critic (RequireCarping)
30 0           move $file, cfg 'spool';
31             }
32              
33             ##################################################
34              
35             sub action {
36 0     0 0   my ($number, $date, $text) = @_;
37 0           my $password = cfg 'password';
38 0           sendsms cfg 'number', <<"EOF"
39             $password
40             $number
41             $date
42             $text
43             EOF
44             }
45              
46             sub psgi {
47 0     0 0   my $correct_password = cfg 'password';
48             sub {
49 0     0     my $r = Plack::Request->new(shift);
50 0           my @numbers = split /,/s, $r->param('numbers');
51 0           my $password = $r->param('password');
52 0 0         return [403, ['Content-Type', 'text/plain'], ['Bad password']] unless $password eq $correct_password;
53 0           my $text = $r->param('text');
54              
55 0           sendsms $_, $text for @numbers
56             }
57 0           }
58              
59             1;
60             __END__