File Coverage

blib/lib/Throwable/SugarFactory.pm
Criterion Covered Total %
statement 24 24 100.0
branch n/a
condition n/a
subroutine 8 8 100.0
pod n/a
total 32 32 100.0


line stmt bran cond sub pod time code
1             package Throwable::SugarFactory;
2              
3 1     1   80982 use strictures 2;
  1         10  
  1         49  
4 1     1   875 use Import::Into;
  1         570  
  1         28  
5 1     1   572 use MooX::SugarFactory ();
  1         2  
  1         21  
6 1     1   4 use Throwable::SugarFactory::Utils '_getglob';
  1         2  
  1         36  
7 1     1   4 use Throwable ();
  1         1  
  1         193  
8              
9             our $VERSION = '0.152700'; # VERSION
10              
11             # ABSTRACT: build a library of syntax-sugared Throwable-based exceptions
12              
13             #
14             # This file is part of Throwable-SugarFactory
15             #
16             #
17             # Christian Walde has dedicated the work to the Commons by waiving all of his
18             # or her rights to the work worldwide under copyright law and all related or
19             # neighboring legal rights he or she had in the work, to the extent allowable by
20             # law.
21             #
22             # Works under CC0 do not require attribution. When citing the work, you should
23             # not imply endorsement by the author.
24             #
25              
26              
27             sub _base_args {
28 3     3   5 my ( $namespace, $error, $description ) = @_;
29             return (
30 3         30 with => [ "Throwable", __PACKAGE__ . "::Hashable" ],
31             has => [ namespace => ( is => 'ro', default => $namespace ) ],
32             has => [ error => ( is => 'ro', default => $error ) ],
33             has => [ description => ( is => 'ro', default => $description ) ],
34             );
35             }
36              
37             sub import {
38 1     1   15 MooX::SugarFactory->import::into( scalar caller ); # I::I 1.001000 syntax
39 1         7 my $factory = caller;
40 1         3 *{ _getglob $factory, "exception" } = sub {
41 3     3   16 my ( $id, $description, @args ) = @_;
42 3         5 my $class = "${factory}::$id";
43 3         9 $factory->can( "class" )->(
44             "$class->throw", _base_args( $factory, $id, $description ), @args
45             );
46 1         3 };
47             }
48              
49             1;
50              
51             __END__