File Coverage

blib/lib/Baseball/Sabermetrics/Team.pm
Criterion Covered Total %
statement 17 36 47.2
branch 2 12 16.6
condition 0 6 0.0
subroutine 5 10 50.0
pod 0 8 0.0
total 24 72 33.3


line stmt bran cond sub pod time code
1             package Baseball::Sabermetrics::Team;
2 2     2   1635 use Baseball::Sabermetrics::abstract;
  2         6  
  2         57  
3 2     2   14 use strict;
  2         3  
  2         1154  
4              
5             our @ISA = qw/ Baseball::Sabermetrics::abstract /;
6              
7             sub players
8             {
9 5     5 0 11 my ($self, $name) = @_;
10 5 50       12 if ($name) {
11 0 0       0 die "Player not found: $name\n" unless exists $self->{players}->{$name};
12 0         0 return $self->{players}->{$name};
13             }
14 5         7 return values %{$self->{players}};
  5         34  
15             }
16              
17             sub pitchers
18             {
19 0     0 0 0 my $self = shift;
20 0 0       0 return grep { exists $_->{np} and $_->{np} > 0 } $self->players;
  0         0  
21             }
22              
23             sub batters
24             {
25 1     1 0 3 my $self = shift;
26 1 50       5 return grep { exists $_->{pa} and $_->{pa} > 0 } $self->players;
  5         32  
27             }
28              
29             sub left_handed_pitchers
30             {
31 0     0 0 0 my $self = shift;
32 0 0 0     0 return grep { exists $_->{np} and $_->{np} > 0 and $_->{bio}->{throws} eq 'left' } $self->players;
  0         0  
33             }
34              
35             sub right_handed_pitchers
36             {
37 0     0 0 0 my $self = shift;
38 0 0 0     0 return grep { exists $_->{np} and $_->{np} > 0 and $_->{bio}->{throws} eq 'right' } $self->players;
  0         0  
39             }
40              
41             sub report
42             {
43 0     0 0 0 my ($self, @cols) = @_;
44 0         0 print join("\t", @cols), "\n";
45 0         0 for ($self->players) {
46 0         0 $_->print(@cols);
47             }
48             }
49              
50             sub report_pitchers
51             {
52 0     0 0 0 my ($self, @cols) = @_;
53 0         0 print join("\t", @cols), "\n";
54 0         0 for ($self->pitchers) {
55 0         0 $_->print(@cols);
56             }
57             }
58              
59             sub report_batters
60             {
61 1     1 0 9 my ($self, @cols) = @_;
62 1         218 print join("\t", @cols), "\n";
63 1         6 for ($self->batters) {
64 5         22 $_->print(@cols);
65             }
66             }
67              
68             1;