GeoIP2/Error/Type.pm

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