Log/Iterator.pm

filter: Statementstmt 90.9% 60 / 66 Branchbran 80.0% 16 / 20 Conditioncond 87.5% 7 / 8 MC/DCmcdc 80.0% 4 / 5 Subroutinesub 83.3% 10 / 12 Podpod 100% 4 / 4 totaltotal 87.8% 101 / 115 CC 15 SCAR 16.8
CC
15
Cov
88%
next
9.0
new
6.0
new_from_file
6.0
CRAP 5.4
↑ Summary Log.pm »
1 package Git::Repository::Log::Iterator;
2 4 $Git::Repository::Log::Iterator::VERSION = '1.314';
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 4 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 ▶use Git::Repository;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Git::Repository::Command;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use Git::Repository::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 22 ▶sub new {
Subroutine new: called CC=6 SCAR=17.9
Pod documented
14 22 my ( $class, @cmd ) = @_;
15  
16 # pick up unsupported log options
17 22 my @badopts = do {
18 22 my $options = 1;
19 62 grep {/^--(?:(?:pretty|format)=(?!raw).*|graph|oneline)$/}
20 22 ▶ grep { $options = 0 if $_ eq '--'; $options } @cmd;
Branch: 1 branch
BranchTrueFalseTotal
if $_ eq "--" 1 63 64
21 };
22 22 ▶ croak "log() cannot parse @badopts. "
Branch: 1 branch
BranchTrueFalseTotal
if @badopts 4 18 22
23 . 'Use run( log => ... ) to parse the output yourself'
24 if @badopts;
25  
26 # note: there is no --color option to git log before 1.5.3.3
27 18 ▶ my ($r) = grep blessed $_ && $_->isa('Git::Repository'), @cmd;
Condition66%2/3
builtin::blessed($_) && $_->isa('Git::Repository')
!ll&&!rl&&r
39017
MC/DC50%1/2
builtin::blessed($_) && $_->isa('Git::Repository')
builtin::blessed($_) $_->isa('Git::Repository')
Truth table66%2/3
A && B
A= builtin::blessed($_)B= $_->isa('Git::Repository')
ABresult
0X0
100
111
28 18 ▶ $r ||= 'Git::Repository'; # no Git::Repository object given
Condition100%2/2
$r ||= "Git::Repository"
l!l
171
MC/DC100%1/1
$r ||= "Git::Repository"
$r
Truth table100%2/2
A
A= $r
Aresult
11
00
29 18 ▶ unshift @cmd, '--no-color' if $r->version_ge('1.5.3.3');
Branch: 1 branch
BranchTrueFalseTotal
if $r->version_ge("1.5.3.3") 18 0 18
30  
31 # enforce the format
32 18 @cmd = ( 'log', '--pretty=raw', @cmd );
33  
34 # run the command (@cmd may hold a Git::Repository instance)
35 18 my $cmd = Git::Repository::Command->new(@cmd);
36 18 bless { cmd => $cmd, fh => $cmd->stdout }, $class;
37 }
38  
39 0 ▶sub new_from_fh {
Subroutine new_from_fh: not called CC=1 SCAR=6.9
Pod documented
40 0 my ( $class, $fh ) = @_;
41 0 bless { fh => $fh }, $class;
42 }
43  
44 0 ▶sub new_from_file {
Subroutine new_from_file: not called CC=2 SCAR=17.9
Pod documented
45 0 my ( $class, $file ) = @_;
46 0 ▶ open my $fh, '<', $file or die "Can't open $file: $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $file or die "Can't open ${file}: $!" 0 0 0
47 0 bless { fh => $fh }, $class;
48 }
49  
50 57 ▶sub next {
Subroutine next: called CC=9 SCAR=22.0
Pod documented
51 57 my ($self) = @_;
52 57 my $fh = $self->{fh};
53  
54 # get records
55 57 ▶ my @records = defined $self->{record} ? ( delete $self->{record} ) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'record'} ? : 25 32 57
56 {
57 57 local $/ = "\n\n";
58 57 ▶ while (<$fh>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $fh)) 90 32 122
59 90 ▶ $self->{record} = $_, last if /\Acommit / && @records;
Branch: 1 branch
BranchTrueFalseTotal
if /\Acommit / and @records 25 65 90
Condition100%3/3
/\Acommit / and @records
!ll&&!rl&&r
501525
MC/DC100%2/2
/\Acommit / and @records
/\Acommit / @records
Truth table100%3/3
A and B
A= /\Acommit /B= @records
ABresult
0X0
100
111
60 65 push @records, $_;
61 }
62 }
63  
64 # EOF
65 57 ▶ if ( !@records ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@records) 17 40 57
66 17 ▶ if ( $self->{cmd} ) { # might catch some git errors
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'cmd'}) { } 17 0 17
67 17 $self->{cmd}->final_output();
68 }
69 else { # just close the filehandle
70 0 $self->{fh}->close;
71 }
72 15 return;
73 }
74  
75 # the first two records are always the same, with --pretty=raw
76 40 local $/ = "\n";
77 40 my ( $header, $message, $extra ) = ( @records, '', '' );
78 40 chomp $header;
79 40 my @headers = map { chomp; split / /, $_, 2 } split /^(?=\S)/m, $header;
80 40 s/\n /\n/g for @headers;
81 40 ▶ chomp( $message, $extra ) if exists $self->{record};
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"record"} 25 15 40
82  
83 # create the log object
84 40 return Git::Repository::Log->new(
85 @headers,
86 message => $message,
87 extra => $extra,
88 );
89 }
90  
91 4 1;
92  
93 __END__
↑ Summary Log.pm »