File Coverage

blib/lib/Math/ModInt/Event.pm
Criterion Covered Total %
statement 63 63 100.0
branch n/a
condition 2 2 100.0
subroutine 22 22 100.0
pod 4 4 100.0
total 91 91 100.0


line stmt bran cond sub pod time code
1             package Math::ModInt::Event;
2              
3 11     11   186 use 5.006;
  11         48  
4 11     11   64 use strict;
  11         26  
  11         259  
5 11     11   57 use warnings;
  11         23  
  11         395  
6 11     11   77 use Carp qw(croak);
  11         22  
  11         811  
7 11     11   6251 use Math::ModInt::Event::Trap;
  11         27  
  11         972  
8              
9             # ----- class data -----
10              
11             BEGIN {
12 11     11   78 require Exporter;
13 11         223 our @ISA = qw(Exporter);
14 11         54 our @EXPORT_OK = qw(
15             AnyEvent Unrecoverable Recoverable UsageError Nonexistent
16             LoadingFailure UndefinedResult DifferentModuli
17             );
18 11         25 our @CARP_NOT = qw(Math::ModInt);
19 11         323 our $VERSION = '0.013';
20             }
21              
22             # Math::ModInt::Event=ARRAY(...)
23              
24             # ............ index ............ # ............ value ............
25 11     11   95 use constant F_DESCRIPTION => 0; # a short event description string
  11         21  
  11         767  
26 11     11   73 use constant NFIELDS => 1;
  11         21  
  11         2119  
27              
28             # ----- private subroutines -----
29              
30             # create a new event subclass and return a singleton instance of that class
31             # - description string is made of the words in the camel-case class name
32             # - parent class is taken from optional parent object or defaults to Event.
33             sub _make {
34 88     88   212 my ($class, $parent) = @_;
35 88         786 my $description = lc join q[ ], split /(?<=[a-z])(?=[A-Z])/, $class;
36 88         231 $class = join '::', __PACKAGE__, $class;
37 88   100     6938 eval join '', '@', $class, '::ISA = qw(', ref $parent || __PACKAGE__, ')';
38 88         7638 return bless [$description], $class;
39             }
40              
41             # ----- public methods -----
42              
43             # singleton event constructors:
44              
45 11     11   86 use constant AnyEvent => _make('AnyEvent');
  11         19  
  11         36  
46 11     11   78 use constant Unrecoverable => _make('Unrecoverable', AnyEvent);
  11         23  
  11         38  
47 11     11   77 use constant UsageError => _make('UsageError', Unrecoverable);
  11         23  
  11         31  
48 11     11   75 use constant Nonexistent => _make('Nonexistent', Unrecoverable);
  11         23  
  11         27  
49 11     11   81 use constant LoadingFailure => _make('LoadingFailure', Unrecoverable);
  11         30  
  11         30  
50 11     11   77 use constant Recoverable => _make('Recoverable', AnyEvent);
  11         45  
  11         50  
51 11     11   73 use constant UndefinedResult => _make('UndefinedResult', Recoverable);
  11         22  
  11         36  
52 11     11   74 use constant DifferentModuli => _make('DifferentModuli', Recoverable);
  11         22  
  11         34  
53              
54             sub description {
55 39     39 1 75 my ($this) = @_;
56 39         4992 return $this->[F_DESCRIPTION];
57             }
58              
59 36     36 1 96 sub is_recoverable { 0 }
60 74     74   212 sub Math::ModInt::Event::Recoverable::is_recoverable { 1 }
61              
62             sub trap {
63 15     15 1 1138 my ($this, $handler) = @_;
64 15         40 return Math::ModInt::Event::Trap->new($this, $handler);
65             }
66              
67             sub raise {
68 114     114 1 249 my ($this, @details) = @_;
69 114         467 Math::ModInt::Event::Trap->broadcast($this, @details);
70 74         134 return $this;
71             }
72              
73             1;
74              
75             __END__