File Coverage

blib/lib/Astro/App/Satpass2/Warner.pm
Criterion Covered Total %
statement 45 59 76.2
branch 9 20 45.0
condition n/a
subroutine 9 10 90.0
pod 5 5 100.0
total 68 94 72.3


line stmt bran cond sub pod time code
1             package Astro::App::Satpass2::Warner;
2              
3 21     21   361 use 5.008;
  21         107  
4              
5 21     21   129 use strict;
  21         37  
  21         658  
6 21     21   109 use warnings;
  21         35  
  21         1257  
7              
8 21     21   4279 use Astro::App::Satpass2::Locale qw{ __message };
  21         61  
  21         1609  
9 21     21   185 use Astro::App::Satpass2::Utils qw{ @CARP_NOT };
  21         38  
  21         17664  
10              
11             our $VERSION = '0.057';
12              
13             sub new {
14 26     26 1 88 my ( $class, @arg ) = @_;
15 26 50       90 ref $class and $class = ref $class;
16 26         62 my $self = {};
17 26         290 bless $self, $class;
18 26         94 while ( @arg ) {
19 7         27 my ( $name, $value ) = splice @arg, 0, 2;
20 7 50       75 my $code = $self->can( $name )
21             or $self->wail( "Warner has no such method as $name" );
22 7         32 $code->( $self, $value );
23             }
24 26         106 return $self;
25             }
26              
27             sub wail {
28 22     22 1 89 my ($self, @args) = @_;
29 22         182 my $msg = __message( @args );
30 22 100       92 ref $msg
31             and die $msg;
32 21         56 chomp $msg;
33 21 50       112 if ($self->warning()) {
34 0 0       0 if ( $Carp::Verbose ) {
35 0         0 require Carp; # Paranoia
36 0         0 Carp::confess( $msg );
37             }
38 0 0       0 $msg =~ m/[.?!]\z/msx or $msg .= '.';
39 0         0 die $msg, "\n";
40             } else {
41 21         133 $msg =~ s/[.?!]\z//msx;
42 21         214 require Carp;
43 21         8974 Carp::croak( $msg );
44             }
45             }
46              
47             sub warning {
48 31     31 1 94 my ( $self, @arg ) = @_;
49 31 100       94 if ( @arg ) {
50 7         45 $self->{warning} = shift @arg;
51 7         29 return $self;
52             } else {
53 24         113 return $self->{warning};
54             }
55             }
56              
57             sub weep {
58 0     0 1 0 my ( undef, @args ) = @_; # Invocant unused
59 0         0 my $msg = join ' ', __message( 'Programming Error -' ), __message( @args );
60 0         0 chomp $msg;
61 0         0 require Carp;
62 0         0 Carp::confess( $msg );
63             }
64              
65             sub whinge {
66 3     3 1 13 my ($self, @args) = @_;
67 3         22 my $msg = __message( @args );
68             ref $msg
69 3 50       43 and do {
70 0         0 warn $msg;
71 0         0 return;
72             };
73 3         14 chomp $msg;
74 3 50       29 if ($self->warning()) {
75 0 0       0 $msg =~ m/ [.?!] \z /msx or $msg .= '.';
76 0         0 warn $msg, "\n";
77             } else {
78 3         39 $msg =~ s/ [.?!] \z //msx;
79 3         89 require Carp;
80 3         920 Carp::carp( $msg );
81             }
82 3         37 return;
83             }
84              
85             1;
86              
87             __END__