line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Geo::Direction::Name::Spec; |
2
|
|
|
|
|
|
|
|
3
|
11
|
|
|
11
|
|
70
|
use warnings; |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
460
|
|
4
|
11
|
|
|
11
|
|
59
|
use strict; |
|
11
|
|
|
|
|
25
|
|
|
11
|
|
|
|
|
408
|
|
5
|
11
|
|
|
11
|
|
64
|
use Carp; |
|
11
|
|
|
|
|
27
|
|
|
11
|
|
|
|
|
983
|
|
6
|
|
|
|
|
|
|
|
7
|
11
|
|
|
11
|
|
66
|
use version; our $VERSION = qv('0.0.4'); |
|
11
|
|
|
|
|
22
|
|
|
11
|
|
|
|
|
98
|
|
8
|
11
|
|
|
11
|
|
2628
|
use Scalar::Util qw(looks_like_number); |
|
11
|
|
|
|
|
36
|
|
|
11
|
|
|
|
|
622
|
|
9
|
11
|
|
|
11
|
|
404
|
use Class::Inspector; |
|
11
|
|
|
|
|
23
|
|
|
11
|
|
|
|
|
102
|
|
10
|
11
|
|
|
11
|
|
302
|
use UNIVERSAL::require; |
|
11
|
|
|
|
|
21
|
|
|
11
|
|
|
|
|
103
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
BEGIN |
13
|
|
|
|
|
|
|
{ |
14
|
11
|
50
|
|
11
|
|
689
|
if ( $] >= 5.006 ) |
15
|
|
|
|
|
|
|
{ |
16
|
11
|
|
|
|
|
51
|
require utf8; import utf8; |
|
11
|
|
|
|
|
70
|
|
17
|
|
|
|
|
|
|
} |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub new { |
21
|
822
|
|
|
822
|
1
|
5895
|
bless { }, $_[0]; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
2141
|
|
|
2141
|
1
|
7287
|
sub devide_num { 32 } |
25
|
|
|
|
|
|
|
|
26
|
1322
|
|
|
1322
|
1
|
4231
|
sub allowed_dev { qw(4 8 16 32) } |
27
|
|
|
|
|
|
|
|
28
|
2
|
|
|
2
|
1
|
8
|
sub default_dev { 8 } |
29
|
|
|
|
|
|
|
|
30
|
165
|
|
|
165
|
1
|
550
|
sub default_locale { "en_US" } |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub locale { |
33
|
2335
|
|
|
2335
|
1
|
3763
|
my $self = shift; |
34
|
2335
|
|
|
|
|
4267
|
my $class_base = ref( $self ); |
35
|
2335
|
|
|
|
|
2975
|
my $locale = shift; |
36
|
2335
|
|
|
|
|
3015
|
my $noerr = shift; |
37
|
2335
|
|
|
|
|
3436
|
my $errstr = "Locale class(subclass of Geo::Direction::Name::Locale) must be set"; |
38
|
2335
|
100
|
66
|
|
|
7373
|
$locale ||= $self->default_locale unless ( $self->{locale} ); |
39
|
|
|
|
|
|
|
|
40
|
2335
|
100
|
|
|
|
5093
|
if ( $locale ) { |
41
|
822
|
|
|
|
|
3342
|
$errstr = "$class_base not support this locale now: " . $locale; |
42
|
822
|
|
|
|
|
2604
|
delete $self->{locale}; |
43
|
|
|
|
|
|
|
|
44
|
822
|
|
|
|
|
3158
|
($locale) = split(/\./,$locale); |
45
|
822
|
|
|
|
|
4095
|
my ($lang) = split(/_/,$locale); |
46
|
|
|
|
|
|
|
|
47
|
822
|
|
|
|
|
9955
|
$class_base =~ s/Spec/Locale/; |
48
|
|
|
|
|
|
|
|
49
|
822
|
|
|
|
|
1503
|
foreach my $class (map { "$class_base\::" . $_ } ($locale, $lang)) { |
|
1644
|
|
|
|
|
18620
|
|
50
|
1316
|
100
|
100
|
|
|
17820
|
if( Class::Inspector->loaded($class) || $class->require) { |
51
|
821
|
|
|
|
|
30496
|
$self->{locale} = $class->new( $self->devide_num ); |
52
|
821
|
|
|
|
|
2123
|
last; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
2335
|
100
|
66
|
|
|
12802
|
croak $errstr unless ( $noerr || $self->{locale} ); |
58
|
2334
|
|
|
|
|
9772
|
$self->{locale}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub to_string { |
62
|
1323
|
|
|
1323
|
1
|
2493
|
my $self = shift; |
63
|
1323
|
|
|
|
|
1961
|
my $direction = shift; |
64
|
1323
|
|
100
|
|
|
3611
|
my $option = shift || {}; |
65
|
|
|
|
|
|
|
|
66
|
1323
|
100
|
|
|
|
3755
|
my $abbr = defined($option->{abbreviation}) ? $option->{abbreviation} : 1; |
67
|
1323
|
|
66
|
|
|
9993
|
my $devide = $option->{devide} || $self->default_dev; |
68
|
|
|
|
|
|
|
|
69
|
1323
|
100
|
|
|
|
11644
|
croak ("Direction value must be a number") unless (looks_like_number($direction)); |
70
|
1322
|
100
|
|
|
|
6393
|
croak ("Abbreviation parameter must be 0 or 1") if ( $abbr !~ /^[01]$/ ); |
71
|
1321
|
100
|
|
|
|
3134
|
croak ("Devide parameter must be ". join( ",", $self->allowed_dev ) ) unless ( grep { $devide == $_ } $self->allowed_dev ); |
|
5284
|
|
|
|
|
14915
|
|
72
|
|
|
|
|
|
|
|
73
|
1320
|
|
|
|
|
5265
|
$direction += 180 / $devide; |
74
|
|
|
|
|
|
|
|
75
|
1320
|
|
66
|
|
|
8207
|
while ($direction < 0.0 || $direction >= 360.0) { |
76
|
110
|
50
|
|
|
|
636
|
$direction += $direction < 0 ? 360.0 : -360.0; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
1320
|
|
|
|
|
4735
|
my $i = int($direction * $devide / 360) * ( $self->devide_num / $devide); |
80
|
|
|
|
|
|
|
|
81
|
1320
|
|
|
|
|
3629
|
$self->locale->string($i,$abbr); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub from_string { |
85
|
193
|
|
|
193
|
1
|
260
|
my $self = shift; |
86
|
193
|
|
|
|
|
257
|
my $string = shift; |
87
|
193
|
|
50
|
|
|
733
|
my $option = shift || {}; |
88
|
|
|
|
|
|
|
|
89
|
193
|
|
|
|
|
418
|
$self->locale->direction($string); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
1; |
93
|
|
|
|
|
|
|
__END__ |