line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package IP::CountryFlag; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$IP::CountryFlag::VERSION = '0.14'; |
4
|
|
|
|
|
|
|
$IP::CountryFlag::AUTHORITY = 'cpan:MANWAR'; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
IP::CountryFlag - Interface to fetch country flag of an IP. |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 VERSION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Version 0.14 |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
2
|
|
|
2
|
|
56764
|
use 5.006; |
|
2
|
|
|
|
|
11
|
|
17
|
2
|
|
|
2
|
|
836
|
use autodie; |
|
2
|
|
|
|
|
26048
|
|
|
2
|
|
|
|
|
8
|
|
18
|
2
|
|
|
2
|
|
13632
|
use IP::CountryFlag::UserAgent; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
65
|
|
19
|
2
|
|
|
2
|
|
879
|
use File::Spec::Functions qw(catfile); |
|
2
|
|
|
|
|
1448
|
|
|
2
|
|
|
|
|
126
|
|
20
|
2
|
|
|
2
|
|
788
|
use IP::CountryFlag::Params qw(validate); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
102
|
|
21
|
|
|
|
|
|
|
|
22
|
2
|
|
|
2
|
|
12
|
use Moo; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
15
|
|
23
|
2
|
|
|
2
|
|
828
|
use namespace::clean; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
14
|
|
24
|
|
|
|
|
|
|
extends 'IP::CountryFlag::UserAgent'; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has 'base_url' => (is => 'ro', default => sub { return 'http://api.hostip.info/flag.php' }); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head1 DESCRIPTION |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
A very thin wrapper for the hostip.info API to get the country flag of an IP address. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 METHOD |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head2 save() |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
Saves the country flag in the given location for the given IP address. It returns the location |
37
|
|
|
|
|
|
|
of the country flag where it has been saved. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
use strict; use warnings; |
40
|
|
|
|
|
|
|
use IP::CountryFlag; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
my $countryFlag = IP::CountryFlag->new; |
43
|
|
|
|
|
|
|
print $countryFlag->save({ ip => '12.215.42.19', path => './' }); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub save { |
48
|
4
|
|
|
4
|
1
|
1716
|
my ($self, $params) = @_; |
49
|
|
|
|
|
|
|
|
50
|
4
|
|
|
|
|
10
|
my $fields = { 'ip' => 1, 'path' => 1 }; |
51
|
4
|
|
|
|
|
9
|
my $url = $self->_url($fields, $params); |
52
|
0
|
|
|
|
|
0
|
my $response = $self->get($url); |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
return _save($params, $response->{content}); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# |
58
|
|
|
|
|
|
|
# |
59
|
|
|
|
|
|
|
# PRIVATE METHODS |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _save { |
62
|
0
|
|
|
0
|
|
0
|
my ($params, $data) = @_; |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
|
|
0
|
my $flag = catfile($params->{path}, $params->{ip} . ".gif"); |
65
|
0
|
|
|
|
|
0
|
eval { |
66
|
0
|
|
|
|
|
0
|
open(my $FLAG, ">$flag"); |
67
|
0
|
|
|
|
|
0
|
binmode($FLAG); |
68
|
0
|
|
|
|
|
0
|
print $FLAG $data; |
69
|
0
|
|
|
|
|
0
|
close $FLAG; |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
0
|
return $flag; |
72
|
|
|
|
|
|
|
}; |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
0
|
die("ERROR: Couldn't save flag [$flag][$@].\n") if $@; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _url { |
78
|
4
|
|
|
4
|
|
6
|
my ($self, $fields, $params) = @_; |
79
|
|
|
|
|
|
|
|
80
|
4
|
|
|
|
|
14
|
validate($fields, $params); |
81
|
|
|
|
|
|
|
|
82
|
0
|
|
|
|
|
|
return sprintf("%s?ip=%s", $self->base_url, $params->{ip}); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 AUTHOR |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Mohammad S Anwar, C<< >> |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=head1 REPOSITORY |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
L |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 BUGS |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Please report any bugs / feature requests to C, |
96
|
|
|
|
|
|
|
or through the web interface at L. |
97
|
|
|
|
|
|
|
I will be notified & then you'll automatically be notified of progress on your bug |
98
|
|
|
|
|
|
|
as I make changes. |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 SUPPORT |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
perldoc IP::CountryFlag |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
You can also look for information at: |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=over 4 |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
L |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
L |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=item * CPAN Ratings |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
L |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=item * Search CPAN |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
L |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=back |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Copyright (C) 2011 - 2017 Mohammad S Anwar. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it under |
133
|
|
|
|
|
|
|
the terms of the the Artistic License (2.0). You may obtain a copy of the full |
134
|
|
|
|
|
|
|
license at: |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
L |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Any use, modification, and distribution of the Standard or Modified Versions is |
139
|
|
|
|
|
|
|
governed by this Artistic License.By using, modifying or distributing the Package, |
140
|
|
|
|
|
|
|
you accept this license. Do not use, modify, or distribute the Package, if you do |
141
|
|
|
|
|
|
|
not accept this license. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
If your Modified Version has been derived from a Modified Version made by someone |
144
|
|
|
|
|
|
|
other than you,you are nevertheless required to ensure that your Modified Version |
145
|
|
|
|
|
|
|
complies with the requirements of this license. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
This license does not grant you the right to use any trademark, service mark, |
148
|
|
|
|
|
|
|
tradename, or logo of the Copyright Holder. |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
This license includes the non-exclusive, worldwide, free-of-charge patent license |
151
|
|
|
|
|
|
|
to make, have made, use, offer to sell, sell, import and otherwise transfer the |
152
|
|
|
|
|
|
|
Package with respect to any patent claims licensable by the Copyright Holder that |
153
|
|
|
|
|
|
|
are necessarily infringed by the Package. If you institute patent litigation |
154
|
|
|
|
|
|
|
(including a cross-claim or counterclaim) against any party alleging that the |
155
|
|
|
|
|
|
|
Package constitutes direct or contributory patent infringement,then this Artistic |
156
|
|
|
|
|
|
|
License to you shall terminate on the date that such litigation is filed. |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND |
159
|
|
|
|
|
|
|
CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED |
160
|
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR |
161
|
|
|
|
|
|
|
NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS |
162
|
|
|
|
|
|
|
REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, |
163
|
|
|
|
|
|
|
INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE |
164
|
|
|
|
|
|
|
OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
DEAFilter API itself is distributed under the terms of the Gnu GPLv3 licence. |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=cut |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
1; # End of IP::CountryFlag |