Mojolicious/Command/sendgrid/mail/send.pm untested

filter: Statementstmt 0.0% 0 / 24 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 42 CC 2 SCAR 11.5
CC
2
Cov
0%
run
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.1
1 package Mojolicious::Command::sendgrid::mail::send;
2 use Mojo::Base 'Mojolicious::Command';
3  
4 use Mojo::JSON 'j';
5 use Mojo::Sendgrid;
6  
7 use Data::Dumper;
8 use Getopt::Long qw(GetOptionsFromArray :config no_auto_abbrev no_ignore_case);
9  
10 has description => 'sendgrid mail send';
11 has usage => sub { shift->extract_usage };
12  
13 has sendgrid => sub { Mojo::Sendgrid->new(shift->app->config('sendgrid')) };
14  
15 sub run {
16 my ($self, @args) = @_;
17  
18 GetOptionsFromArray \@args,
19 't|to=s' => \my $to,
20 'f|from=s' => \my $from,
21 's|subject=s' => \my $subject;
22  
23 die $self->usage unless $to && $from && $subject;
24  
25 say Data::Dumper::Dumper $self->sendgrid->mail(to=>$to,from=>$from,subject=>$subject,text=>join("\n",<STDIN>))->send->res->json;
26 }
27  
28 1;
29  
30 =encoding utf8
31  
32 =head1 NAME
33  
34 Mojolicious::Command::sendgrid::mail::send - Send command of the Sendgrid API
35 mail endpoint.
36  
37 =head1 SYNOPSIS
38  
39 Usage: APPLICATION sendgrid mail send [OPTIONS]
40  
41 export SENDGRID_APIKEY='your sendgrid api key'
42 mojo sendgrid mail send -t a@b.com -f x@y.com -s Subject < /tmp/file
43  
44 Options:
45 -h, --help Show this summary of available options
46 -t, --to Email address of the recipient
47 -f, --from Email address of the sender
48 -s, --subject Subject of the email
49  
50 =head1 DESCRIPTION
51  
52 L<Mojolicious::Command::sendgrid::mail::send> sends emails.
53 Prints the json response to STDOUT.
54  
55 =head1 ATTRIBUTES
56  
57 L<Mojolicious::Command::sendgrid::mail::send> inherits all attributes from
58 L<Mojolicious::Command> and implements the following new ones.
59  
60 =head2 description
61  
62 my $description = $app->description;
63 $app = $app->description('Foo');
64  
65 Short description of this command, used for the command list.
66  
67 =head2 usage
68  
69 my $usage = $app->usage;
70 $app = $app->usage('Foo');
71  
72 Usage information for this command, used for the help screen.
73  
74 =head1 METHODS
75  
76 L<Mojolicious::Command::sendgrid::mail::send> inherits all methods from
77 L<Mojolicious::Command> and implements the following new ones.
78  
79 =head2 run
80  
81 $app->run(@ARGV);
82  
83 Run this command.
84  
85 =head1 SEE ALSO
86  
87 L<Mojolicious>, L<Mojolicious::Guides>, L<http://mojolicious.org>.
88  
89 =cut