blib/lib/Chess/Mbox.pm

filter: Statementstmt 95.5% 43 / 45 Branchbran 66.6% 8 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 5 / 5 Podpod 0.0% 0 / 1 totaltotal 88.8% 56 / 63 CC 7 SCAR 15.9
CC
7
Cov
89%
Parse
7.1
BEGIN
1.0
BEGIN
1.0
CRAP 4.9
↑ Summary
1 package Chess::Mbox;
2  
3 1 ▶use Chess::PGN::Parse;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use Mail::MboxParser;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6  
7 1 require 5.005_62;
8 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our $VERSION = sprintf '%s', 'q$Revision: 1.3 $' =~ /\S+\s+(\S+)\s+/ ;
12  
13  
14 # Preloaded methods go here.
15  
16 1 ▶sub Parse {
Subroutine Parse: called CC=7 SCAR=19.7
Pod undocumented
17 1 my $class = shift;
18 1 my %C = @_;
19  
20 1 my $mailbox = $C{mbox};
21 1 my $game_dir = $C{output_dir};
22 1 my $postop = $C{post_op};
23 1 warn "POSTOP: $postop";
24 1 my $temp_file = "/tmp/chessfile$$";
25  
26 1 my $mb = Mail::MboxParser->new($mailbox, decode => 'NEVER');
27  
28 1 ▶while (my $msg = $mb->next_message) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $msg = $mb->next_message) 3 1 4
29 3 print $msg->header->{subject}, "\n";
30  
31 3 my $pgnfile = $temp_file;
32 3 ▶ open T, ">$pgnfile" or die "couldnt open $pgnfile: $!";
Branch: 1 branch
BranchTrueFalseTotal
open T, ">$pgnfile" or die "couldnt open ${pgnfile}: $!" 3 0 3
33 3 my $GAME = $msg->body($msg->find_body)->as_string;
34 3 print T $GAME;
35 3 close(T);
36  
37 3 ▶ my $pgn = Chess::PGN::Parse->new($pgnfile) or die "can't open $pgnfile\n";
Branch: 1 branch
BranchTrueFalseTotal
my $pgn = "Chess::PGN::Parse"->new($pgnfile) or die "can't open $pgnfile\n" 3 0 3
38  
39 3 ▶ while ($pgn->read_game) {
Branch: 1 branch
BranchTrueFalseTotal
if ($pgn->read_game) 3 3 6
40 3 mkdir sprintf "%s/%s", $game_dir, $pgn->white;
41 3 my $dir = sprintf "%s/%s/%s", $game_dir, $pgn->white, $pgn->black;
42 3 mkdir $dir;
43 3 my $file = sprintf "%s-%s", $pgn->date, $pgn->time;
44 3 $file =~ s/:/-/g;
45 3 my $F = "$dir/$file.pgn";
46 3 print $F, $/;
47 3 ▶ open F, ">$F" or die "couldnt open $F: $!";
Branch: 1 branch
BranchTrueFalseTotal
open F, ">$F" or die "couldnt open ${F}: $!" 3 0 3
48 3 print F $GAME;
49 3 close(F);
50 3 ▶ if ($postop) {
Branch: 1 branch
BranchTrueFalseTotal
if ($postop) 0 3 3
51 0 chdir $dir;
52 0 &$postop;
53 }
54 }
55  
56 }
57  
58  
59  
60  
61 }
62  
63 1 1;
64 __END__
↑ Summary