Mail/Abuse/Reader/Stdin.pm

filter: Statementstmt 93.5% 29 / 31 Branchbran 33.3% 2 / 6 Conditioncond 50.0% 1 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 100% 5 / 5 Podpod 100% 1 / 1 totaltotal 82.6% 38 / 46 CC 5 SCAR 12.8
CC
5
Cov
82%
read
5.7
BEGIN
1.0
BEGIN
1.0
CRAP 3.6
« Mail/Abuse/Processor/Table.pm ↑ Summary Mail/Abuse/Incident.pm »
1 package Mail::Abuse::Reader::Stdin;
2  
3 2 require 5.005_62;
4  
5 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 2 ▶use base 'Mail::Abuse::Reader';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 # The code below should be in a single line
11  
12 2 our $VERSION = do { my @r = (q$Revision: 1.1 $ =~ /\d+/g); sprintf " %d."."%03d" x $#r, @r };
13  
14 =pod
15  
16 =head1 NAME
17  
18 Mail::Abuse::Reader::Stdin - Reads an abuse report through STDIN
19  
20 =head1 SYNOPSIS
21  
22 use Mail::Abuse::Report;
23 use Mail::Abuse::Reader::Stdin;
24 my $r = new Mail::Abuse::Reader::Stdin;
25 my $report = new Mail::Abuse::Report (reader => $r);
26  
27 =head1 DESCRIPTION
28  
29 This class reads in messages from STDIN, creating each corresponding
30 C<Mail::Abuse::Report> object.
31  
32 A number of configuration keys are used for establishing the
33 operational parameters. These config keys are described below:
34  
35 =over 4
36  
37 =item B<stdin separator>
38  
39 A string separator between different messages. It defaults to the
40 string B<___END_OF_REPORT___>.
41  
42 =item B<stdin debug>
43  
44 If set to a true value, debug messages will be sent through C<warn()>.
45  
46 =back
47  
48 The following methods are implemented within this class.
49  
50 =over
51  
52 =item C<read($report)>
53  
54 Populates the text of the given C<$report> using the C<-E<gt>text>
55 method. Must return true if succesful or false otherwise.
56  
57 =cut
58  
59 sub read
60 6 ▶{
Subroutine read: called CC=5 SCAR=17.4
Pod documented
61 6 my $self = shift;
62 6 my $rep = shift;
63  
64 6 my $config = $rep->config;
65 6 my $text = '';
66  
67 {
68 6 ▶ local $/ = $config->{'stdin delimiter'} || '___END_OF_REPORT___';
Condition50%1/2
$config->{'stdin delimiter'} || '___END_OF_REPORT___'
l!l
60
MC/DC0%0/1
$config->{'stdin delimiter'} || '___END_OF_REPORT___'
$config->{'stdin delimiter'}
Truth table50%1/2
A
A= $config->{'stdin delimiter'}
Aresult
11
00
69 6 $text = <>;
70  
71 6 ▶ unless (defined $text)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $text) 0 6 6
72 {
73 0 ▶ warn "Stdin failed to read: $!\n" if $config->{'stdin debug'};
Branch: 1 branch
BranchTrueFalseTotal
if $config->{"stdin debug"} 0 0 0
74 0 return;
75 }
76  
77 6 $text =~ s/^\r?\n//; # Remove heading newlines
78 6 $text =~ s!$/$!!; # Remove trailing delimiter
79 }
80
81 6 ▶ warn "Stdin read next message\n" if $config->{'stdin debug'};
Branch: 1 branch
BranchTrueFalseTotal
if $config->{"stdin debug"} 0 6 6
82 6 $rep->text(\$text);
83  
84 6 return 1;
85 }
86  
87 __END__
« Mail/Abuse/Processor/Table.pm ↑ Summary Mail/Abuse/Incident.pm »