File Coverage

blib/lib/App/MaMGal/Exceptions.pm
Criterion Covered Total %
statement 50 59 84.7
branch 8 14 57.1
condition 0 4 0.0
subroutine 15 18 83.3
pod n/a
total 73 95 76.8


line stmt bran cond sub pod time code
1             # mamgal - a program for creating static image galleries
2             # Copyright 2007-2009 Marcin Owsiany
3             # See the README file for license information
4             # Exception class definitions.
5             package App::MaMGal::Exceptions;
6 10     10   923 use strict;
  10         17  
  10         294  
7 10     10   51 use warnings;
  10         16  
  10         204  
8 10     10   60 use Carp;
  10         17  
  10         975  
9             use Exception::Class (
10 10         128 'App::MaMGal::MplayerWrapper::NotAvailableException',
11             'App::MaMGal::MplayerWrapper::ExecutionFailureException' => {
12             fields => [qw(stdout stderr)],
13             },
14             'App::MaMGal::SystemException' => {
15             fields => [qw(objects)],
16             }
17 10     10   203113 );
  10         940474  
18              
19             package App::MaMGal::MplayerWrapper::NotAvailableException;
20 10     10   7896 use strict;
  10         22  
  10         279  
21 10     10   58 use warnings;
  10         19  
  10         284  
22 10     10   50 use Carp;
  10         53  
  10         1435  
23              
24             sub _initialize
25             {
26 0     0   0 my $self = shift;
27 0 0       0 croak "this exception does not accept arguments" if @_;
28 0         0 $self->SUPER::_initialize(@_);
29             }
30              
31             sub message
32             {
33 0     0   0 my $self = shift;
34 0         0 'mplayer is not available - films will not be represented by snapshots.'
35             }
36              
37             package App::MaMGal::MplayerWrapper::ExecutionFailureException;
38 10     10   55 use strict;
  10         25  
  10         429  
39 10     10   57 use warnings;
  10         34  
  10         254  
40 10     10   48 use Carp;
  10         172  
  10         1246  
41              
42             sub _initialize
43             {
44 0     0   0 my $self = shift;
45 0         0 $self->SUPER::_initialize(@_);
46 0 0       0 croak "This exception requires a message argument" unless $self->message;
47 0 0 0     0 croak "Either one or three arguments are required" if $self->stdout xor $self->stderr;
48             }
49              
50             package App::MaMGal::SystemException;
51 10     10   61 use strict;
  10         15  
  10         272  
52 10     10   43 use warnings;
  10         19  
  10         275  
53 10     10   43 use Carp;
  10         19  
  10         2596  
54              
55             sub _initialize
56             {
57 7     7   7347 my $self = shift;
58 7         101 $self->SUPER::_initialize(@_);
59 7 100       4794 croak "This exception requires a message argument" unless $self->message;
60             # zero-width negative look-ahead assertion: a percent not followed by percent
61 6         38 my $placeholder_count = () = $self->message =~ /%(?!%)/g;
62 6 100       197 my $object_count = $self->objects ? scalar @{$self->objects} : 0;
  4         98  
63 6 100       78 croak "Message with $placeholder_count placeholders must be followed by this many arguments, not $object_count" unless $placeholder_count == $object_count;
64             }
65              
66             sub interpolated_message
67             {
68 2     2   2775 my $self = shift;
69 2 100       55 my @args = $self->objects ? @{$self->objects} : ();
  1         28  
70 2         19 sprintf($self->message, @args);
71             }
72              
73             1;