File Coverage

blib/lib/GeoIP2/Record/City.pm
Criterion Covered Total %
statement 15 15 100.0
branch n/a
condition n/a
subroutine 5 5 100.0
pod n/a
total 20 20 100.0


line stmt bran cond sub pod time code
1             package GeoIP2::Record::City;
2              
3 12     12   69 use strict;
  12         16  
  12         279  
4 12     12   48 use warnings;
  12         17  
  12         455  
5              
6             our $VERSION = '2.006002';
7              
8 12     12   72 use Moo;
  12         19  
  12         54  
9              
10 12     12   3535 use GeoIP2::Types qw( NonNegativeInt PositiveInt Str );
  12         23  
  12         644  
11              
12 12     12   74 use namespace::clean -except => 'meta';
  12         32  
  12         65  
13              
14             with 'GeoIP2::Role::Record::HasNames';
15              
16             has confidence => (
17             is => 'ro',
18             isa => NonNegativeInt,
19             predicate => 'has_confidence',
20             );
21              
22             has geoname_id => (
23             is => 'ro',
24             isa => PositiveInt,
25             predicate => 'has_geoname_id',
26             );
27              
28             1;
29              
30             # ABSTRACT: Contains data for the city record associated with an IP address
31              
32             __END__
33              
34             =pod
35              
36             =encoding UTF-8
37              
38             =head1 NAME
39              
40             GeoIP2::Record::City - Contains data for the city record associated with an IP address
41              
42             =head1 VERSION
43              
44             version 2.006002
45              
46             =head1 SYNOPSIS
47              
48             use 5.008;
49              
50             use GeoIP2::WebService::Client;
51              
52             my $client = GeoIP2::WebService::Client->new(
53             account_id => 42,
54             license_key => 'abcdef123456',
55             );
56              
57             my $insights = $client->insights( ip => '24.24.24.24' );
58              
59             my $city_rec = $insights->city();
60             print $city_rec->name(), "\n";
61              
62             =head1 DESCRIPTION
63              
64             This class contains the city-level data associated with an IP address.
65              
66             This record is returned by all the end points except the Country end point.
67              
68             =head1 METHODS
69              
70             This class provides the following methods:
71              
72             =head2 $city_rec->confidence()
73              
74             This returns a value from 0-100 indicating MaxMind's confidence that the city
75             is correct.
76              
77             This attribute is only available from the Insights end point and the GeoIP2
78             Enterprise database.
79              
80             =head2 $city_rec->geoname_id()
81              
82             This returns a C<geoname_id> for the city.
83              
84             This attribute is returned by all end points.
85              
86             =head2 $city_rec->name()
87              
88             This returns a name for the city. The locale chosen depends on the C<locales>
89             argument that was passed to the record's constructor. This will be passed
90             through from the L<GeoIP2::WebService::Client> object you used to fetch the
91             data that populated this record.
92              
93             If the record does not have a name in any of the locales you asked for, this
94             method returns C<undef>.
95              
96             This attribute is returned by all end points.
97              
98             =head2 $city_rec->names()
99              
100             This returns a hash reference where the keys are locale codes and the values
101             are names. See L<GeoIP2::WebService::Client> for a list of the possible
102             locale codes.
103              
104             This attribute is returned by all end points.
105              
106             =head1 SUPPORT
107              
108             Bugs may be submitted through L<https://github.com/maxmind/GeoIP2-perl/issues>.
109              
110             =head1 AUTHORS
111              
112             =over 4
113              
114             =item *
115              
116             Dave Rolsky <drolsky@maxmind.com>
117              
118             =item *
119              
120             Greg Oschwald <goschwald@maxmind.com>
121              
122             =item *
123              
124             Mark Fowler <mfowler@maxmind.com>
125              
126             =item *
127              
128             Olaf Alders <oalders@maxmind.com>
129              
130             =back
131              
132             =head1 COPYRIGHT AND LICENSE
133              
134             This software is copyright (c) 2013 - 2019 by MaxMind, Inc.
135              
136             This is free software; you can redistribute it and/or modify it under
137             the same terms as the Perl 5 programming language system itself.
138              
139             =cut