Spoor/TransmissionFormatter.pm

filter: Statementstmt 100% 17 / 17 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 96.6% 29 / 30 CC 5 SCAR 12.5
CC
5
Cov
96%
format
5.0
BEGIN
1.0
BEGIN
1.0
CRAP 3.5
« Spoor/Installer.pm ↑ Summary Spoor/ErrorEntryParser.pm »
1 package App::Spoor::TransmissionFormatter;
2  
3 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 =head1 NAME
8  
9 App::Spoor::TransmissionFormatter
10  
11 =head1 VERSION
12  
13 Version 0.01
14  
15 =cut
16  
17 1 our $VERSION = '0.01';
18  
19  
20 =head1 SYNOPSIS
21  
22 Transforms the format of an item so that it is suitable for submission to the Spoor API.
23  
24 =head1 SUBROUTINES
25  
26 =head2 format
27  
28 Takes a hash representation of a hash as input and returns an entry converted into a format suitable for submission to
29 the Spoor API.
30  
31 use Sys::Hostname;
32 my $host = hostname;
33  
34 my %login_entry = (
35 type => 'login',
36 event => 'login',
37 log_time => DateTime->new(
38 year => 2018,
39 month => 9,
40 day => 19,
41 hour => 16,
42 minute => 2,
43 second => 36,
44 time_zone => '+0000'
45 )->epoch(),
46 scope => 'webmaild',
47 ip => '10.10.10.10',
48 credential => 'rorymckinley@blah.capefox.co',
49 possessor => 'blahuser',
50 status => 'success',
51 context => 'foobar'
52 );
53  
54 $formatted_entry = App::Spoor::TransmissionFormatter.format(\%login_entry, $host);
55  
56 =cut
57  
58 4 ▶sub format {
Subroutine format: called CC=5 SCAR=16.1
Pod documented
59 4 my $entry = shift;
60 4 my $host = shift;
61  
62 4 ▶ if($entry->{event} eq 'login') {
Branch: 4 branches
BranchTrueFalseTotal
if ($entry->{'event'} eq 'login') { } 1 3 4
elsif ($entry->{'event'} eq 'forward_added_partial_ip') { } 1 2 3
elsif ($entry->{'event'} eq 'forward_added_partial_recipient') { } 1 1 2
elsif ($entry->{'event'} eq 'forward_removed') { } 1 0 1
63 {
64 type => $entry->{event},
65 time => $entry->{log_time},
66 ip => $entry->{ip},
67 mailbox_address => $entry->{credential},
68 context => $entry->{context},
69 1 host => $host
70 }
71 } elsif($entry->{event} eq 'forward_added_partial_ip') {
72 {
73 type => $entry->{event},
74 time => $entry->{log_time},
75 ip => $entry->{ip},
76 mailbox_address => $entry->{credential},
77 context => $entry->{context},
78 1 host => $host
79 }
80 } elsif($entry->{event} eq 'forward_added_partial_recipient') {
81 {
82 type => $entry->{event},
83 time => $entry->{log_time},
84 mailbox_address => $entry->{email},
85 forward_recipient => $entry->{forward_to},
86 context => $entry->{context},
87 1 host => $host
88 }
89 } elsif($entry->{event} eq 'forward_removed') {
90 {
91 type => $entry->{event},
92 time => $entry->{log_time},
93 mailbox_address => $entry->{credential},
94 forward_recipient => $entry->{forward_recipient},
95 ip => $entry->{ip},
96 context => $entry->{context},
97 1 host => $host
98 }
99 }
100 }
101  
102 =head1 AUTHOR
103  
104 Rory McKinley, C<< <rorymckinley at capefox.co> >>
105  
106 =head1 BUGS
107  
108 Please report any bugs or feature requests to C<bug-. at rt.cpan.org>, or through
109 the web interface at L<https://rt.cpan.org/NoAuth/ReportBug.html?Queue=.>. I will be notified, and then you'll
110 automatically be notified of progress on your bug as I make changes.
111  
112 =head1 SUPPORT
113  
114 You can find documentation for this module with the perldoc command.
115  
116 perldoc App::Spoor::TransmissionFormatter
117  
118  
119 You can also look for information at:
120  
121 =over 4
122  
123 =item * RT: CPAN's request tracker (report bugs here)
124  
125 L<https://rt.cpan.org/NoAuth/Bugs.html?Dist=.>
126  
127 =item * AnnoCPAN: Annotated CPAN documentation
128  
129 L<http://annocpan.org/dist/.>
130  
131 =item * CPAN Ratings
132  
133 L<https://cpanratings.perl.org/d/.>
134  
135 =item * Search CPAN
136  
137 L<https://metacpan.org/release/.>
138  
139 =back
140  
141 =head1 LICENSE AND COPYRIGHT
142  
143 Copyright 2019 Rory McKinley.
144  
145 This program is free software; you can redistribute it and/or modify it
146 under the terms of the the Artistic License (2.0). You may obtain a
147 copy of the full license at:
148  
149 L<http://www.perlfoundation.org/artistic_license_2_0>
150  
151 Any use, modification, and distribution of the Standard or Modified
152 Versions is governed by this Artistic License. By using, modifying or
153 distributing the Package, you accept this license. Do not use, modify,
154 or distribute the Package, if you do not accept this license.
155  
156 If your Modified Version has been derived from a Modified Version made
157 by someone other than you, you are nevertheless required to ensure that
158 your Modified Version complies with the requirements of this license.
159  
160 This license does not grant you the right to use any trademark, service
161 mark, tradename, or logo of the Copyright Holder.
162  
163 This license includes the non-exclusive, worldwide, free-of-charge
164 patent license to make, have made, use, offer to sell, sell, import and
165 otherwise transfer the Package with respect to any patent claims
166 licensable by the Copyright Holder that are necessarily infringed by the
167 Package. If you institute patent litigation (including a cross-claim or
168 counterclaim) against any party alleging that the Package constitutes
169 direct or contributory patent infringement, then this Artistic License
170 to you shall terminate on the date that such litigation is filed.
171  
172 Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER
173 AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES.
174 THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
175 PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY
176 YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR
177 CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR
178 CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE,
179 EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
180  
181  
182 =cut
183  
184 1 1; # End of App::Spoor::TransmissionFormatter
« Spoor/Installer.pm ↑ Summary Spoor/ErrorEntryParser.pm »