lib/Monitoring/Spooler/Transport/SmsSend.pm untested

filter: Statementstmt 0.0% 0 / 61 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 89 CC 3 SCAR 11.7
CC
3
Cov
0%
provides
6.0
run
6.0
BEGIN
2.0
CRAP 3.2
1 package Monitoring::Spooler::Transport::SmsSend;
2 $Monitoring::Spooler::Transport::SmsSend::VERSION = '0.05';
3 BEGIN {
4 $Monitoring::Spooler::Transport::SmsSend::AUTHORITY = 'cpan:TEX';
5 }
6 # ABSTRACT: a monitoring spooler transport using the SMS::Send framework
7  
8 use 5.010_000;
9 use mro 'c3';
10 use feature ':5.10';
11  
12 use Moose;
13 use namespace::autoclean;
14  
15 # use IO::Handle;
16 # use autodie;
17 # use MooseX::Params::Validate;
18 # use Carp;
19 # use English qw( -no_match_vars );
20 # use Try::Tiny;
21 use SMS::Send;
22  
23 # extends ...
24 extends 'Monitoring::Spooler::Transport';
25 # has ...
26 has '_sender' => (
27 'is' => 'rw',
28 'isa' => 'SMS::Send',
29 'lazy' => 1,
30 'builder' => '_init_sender',
31 );
32  
33 has 'driver' => (
34 'is' => 'ro',
35 'isa' => 'Str',
36 'required' => 1,
37 );
38  
39 has 'privargs' => (
40 'is' => 'ro',
41 'isa' => 'HashRef',
42 'required' => 1,
43 );
44 # with ...
45 # initializers ...
46 sub _init_sender {
47 my $self = shift;
48  
49 my $Sender = SMS::Send::->new($self->driver(), %{$self->privargs()},);
50  
51 return $Sender;
52 }
53  
54 around BUILDARGS => sub {
55 my $orig = shift;
56 my $class = shift;
57  
58 if ( @_ == 1 && ref $_[0] ) {
59 # move private SMS::Send args to privargs hash ...
60 my $privargs = {};
61 foreach my $key (keys %{$_[0]}) {
62 if($key =~ m/^_/) {
63 $privargs->{$key} = $_[0]->{$key};
64 delete $_[0]->{$key};
65 }
66 }
67 $_[0]->{'privargs'} = $privargs;
68 return $class->$orig( $_[0] );
69 }
70 else {
71 return $class->$orig(@_);
72 }
73 # direct hash calling style is not supported yet
74 };
75  
76 # your code here ...
77 sub provides {
78 my $self = shift;
79 my $type = shift;
80  
81 if($type =~ m/^text$/i) {
82 return 1;
83 }
84  
85 return;
86 }
87  
88 sub run {
89 my $self = shift;
90 my $destination = shift;
91 my $message = shift;
92  
93 $message = substr($message,0,159);
94  
95 my $result = $self->_sender->send_sms(
96 text => $message,
97 to => $destination,
98 );
99  
100 if($result) {
101 $self->logger()->log( message => 'Sent '.$message.' to '.$destination, level => 'debug', );
102 return 1;
103 } else {
104 $self->logger()->log( message => 'Failed to send '.$message.' to '.$destination.'.', level => 'debug', );
105 return;
106 }
107 }
108  
109 no Moose;
110 __PACKAGE__->meta->make_immutable;
111  
112 1;
113  
114 __END__