GeoIP2/Error/Type.pm

filter: Statementstmt 100% 14 / 14 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 17 / 17 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« GeoIP2/Error/IPAddressNotFound.pm ↑ Summary GeoIP2/Error/WebService.pm »
1 package GeoIP2::Error::Type;
2 8 $GeoIP2::Error::Type::VERSION = '0.050000';
3 8 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 8 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 8 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 8 extends 'Throwable::Error';
9  
10 # We can't load GeoIP2::Types to get types here because we'd have a circular
11 # use in that case.
12 8 has type => (
13 is => 'ro',
14 required => 1,
15 );
16  
17 8 has value => (
18 is => 'ro',
19 required => 1,
20 );
21  
22 8 1;
23  
24 # ABSTRACT: A type validation error.
25  
26 __END__
27  
28 =pod
29  
30 =head1 NAME
31  
32 GeoIP2::Error::Type - A type validation error.
33  
34 =head1 VERSION
35  
36 version 0.050000
37  
38 =head1 SYNOPSIS
39  
40 use 5.008;
41  
42 use GeoIP2::WebService::Client;
43 use Scalar::Util qw( blessed );
44 use Try::Tiny;
45  
46 my $client = GeoIP2::WebService::Client->new(
47 user_id => 42,
48 license_key => 'abcdef123456',
49 );
50  
51 try {
52 $client->insights( ip => '24.24.24.24' );
53 }
54 catch {
55 die $_ unless blessed $_;
56 if ( $_->isa('GeoIP2::Error::Type') ) {
57 log_validation_error(
58 type => $_->name(),
59 value => $_->value(),
60 );
61 }
62  
63 # handle other exceptions
64 };
65  
66 =head1 DESCRIPTION
67  
68 This class represents a Moo type validation error. It extends
69 L<Throwable::Error> and adds attributes of its own.
70  
71 =head1 METHODS
72  
73 The C<< $error->message() >>, and C<< $error->stack_trace() >> methods are
74 inherited from L<Throwable::Error>. It also provide two methods of its own:
75  
76 =head2 $error->name()
77  
78 Returns the name of the type which failed validation.
79  
80 =head2 $error->value()
81  
82 Returns the value which triggered the validation failure.
83  
84 =head1 AUTHORS
85  
86 =over 4
87  
88 =item *
89  
90 Dave Rolsky <drolsky@maxmind.com>
91  
92 =item *
93  
94 Greg Oschwald <goschwald@maxmind.com>
95  
96 =item *
97  
98 Olaf Alders <oalders@maxmind.com>
99  
100 =back
101  
102 =head1 COPYRIGHT AND LICENSE
103  
104 This software is copyright (c) 2014 by MaxMind, Inc..
105  
106 This is free software; you can redistribute it and/or modify it under
107 the same terms as the Perl 5 programming language system itself.
108  
109 =cut
« GeoIP2/Error/IPAddressNotFound.pm ↑ Summary GeoIP2/Error/WebService.pm »