File Coverage

lib/SweetPea/Cli/Error.pm
Criterion Covered Total %
statement 9 30 30.0
branch 0 2 0.0
condition n/a
subroutine 3 8 37.5
pod 0 5 0.0
total 12 45 26.6


line stmt bran cond sub pod time code
1             package SweetPea::Cli::Error;
2            
3 1     1   10 use warnings;
  1         2  
  1         67  
4 1     1   6 use strict;
  1         2  
  1         39  
5            
6 1     1   7 use SweetPea::Cli::Util;
  1         3  
  1         531  
7            
8             # SweetPea::Cli::Error - Error handling for SweetPea-Cli.
9            
10             sub new {
11 0     0 0   my ($class, $s) = @_;
12 0           my $self = {};
13 0           bless $self, $class;
14 0           $self->{base} = $s;
15 0           $self->{errors} = [];
16 0           return $self;
17             }
18            
19             # error # The error method is responsible for storing passed in error messages
20             # for later retrieval and rendering.
21            
22             sub error {
23 0     0 0   my $self = shift;
24 0           foreach my $message (@_) {
25 0           push @{$self->{errors}}, $message;
  0            
26             }
27 0           return $self;
28             }
29            
30             # count
31             # The count method returns the number of error messages currently
32             # existing in the error messages container.
33            
34             sub count {
35 0     0 0   return @{shift->{errors}};
  0            
36             }
37            
38             # clear
39             # The clear method resets the error message container.
40            
41             sub clear {
42 0     0 0   shift->{errors} = [];
43             }
44            
45             # report
46             # The report method is responsible for displaying all stored error
47             # messages using the defined message delimiter.
48            
49             sub report {
50 0     0 0   my $self = shift;
51 0           my $c = shift;
52 0           my $u = SweetPea::Cli::Util->new;
53 0 0         if ($c) {
54 0           $c->stash->{errors} = $self->{errors};
55 0           $self->clear;
56 0           return $u->template('misc/error_string.tt', $c);
57             }
58             }
59            
60             1; # End of SweetPea::Cli::Error