File Coverage

blib/lib/Data/Stack.pm
Criterion Covered Total %
statement 26 34 76.4
branch 4 4 100.0
condition 1 3 33.3
subroutine 7 10 70.0
pod 8 8 100.0
total 46 59 77.9


line stmt bran cond sub pod time code
1             package Data::Stack;
2 1     1   47835 use strict;
  1         3  
  1         47  
3 1     1   6 use warnings;
  1         2  
  1         1135  
4              
5             our $VERSION = '0.01';
6              
7             sub new {
8 2     2 1 15 my $proto = shift();
9 2   33     12 my $class = ref($proto) || $proto;
10              
11 2         4 my $self = [];
12 2 100       8 if(@_) {
13 1         2 push(@{ $self }, @_);
  1         4  
14             }
15              
16 2         8 return bless($self, $class);
17             }
18              
19             sub peek {
20 0     0 1 0 my $self = shift();
21              
22 0         0 return $self->get(0);
23             }
24              
25             sub clear {
26 0     0 1 0 my $self = shift();
27              
28 0         0 $#{ $self } = -1;
  0         0  
29             }
30              
31             sub get {
32 0     0 1 0 my $self = shift();
33 0         0 my $index = shift();
34              
35 0         0 return $self->[$index];
36             }
37              
38             sub count {
39 9     9 1 13 my $self = shift();
40              
41 9         11 return $#{ $self } + 1;
  9         49  
42             }
43              
44             sub empty {
45 4     4 1 1063 my $self = shift();
46              
47 4 100       11 if($self->count() == 0) {
48 3         13 return 1;
49             }
50              
51 1         5 return 0;
52             }
53              
54             sub pop {
55 3     3 1 6 my $self = shift();
56              
57 3         4 return shift(@{ $self });
  3         15  
58             }
59              
60             sub push {
61 1     1 1 3 my $self = shift();
62              
63 1         2 unshift(@{ $self }, shift());
  1         3  
64             }
65              
66             1;
67             __END__