Changeset 31677
- Timestamp:
- 03/30/09 00:04:44 (4 years ago)
- Location:
- lang/perl/Geo-Direction-Name/trunk
- Files:
-
- 7 added
- 8 modified
-
Changes (modified) (1 diff)
-
MANIFEST (modified) (2 diffs)
-
lib/Geo/Direction/Name.pm (modified) (5 diffs)
-
lib/Geo/Direction/Name/Locale.pm (modified) (4 diffs)
-
lib/Geo/Direction/Name/Locale/ja.pm (modified) (1 diff)
-
lib/Geo/Direction/Name/Locale/zh_CN.pm (added)
-
lib/Geo/Direction/Name/Locale/zh_TW.pm (added)
-
lib/Geo/Direction/Name/Spec.pm (added)
-
t/01-2.ja_string.t (modified) (3 diffs)
-
t/01-4.zh_CN_string.t (added)
-
t/01-5.zh_TW_string.t (added)
-
t/02-2.ja_dir.t (modified) (1 diff)
-
t/02-4.zh_CN_dir.t (added)
-
t/02-5.zh_TW_dir.t (added)
-
t/03.error.t (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Geo-Direction-Name/trunk/Changes
r21013 r31677 1 1 Revision history for Geo-Direction-Name 2 3 0.0.4 Sun Mar 29 2009 4 - Fix the fatal data error of ja locale 5 - Add zh_CN, zh_TW locale 6 - Add direction specification add-on system 2 7 3 8 0.0.3 Thu Oct 09 2008 -
lang/perl/Geo-Direction-Name/trunk/MANIFEST
r21014 r31677 6 6 lib/Geo/Direction/Name/Locale/ja.pm 7 7 lib/Geo/Direction/Name/Locale/ko.pm 8 lib/Geo/Direction/Name/Locale/zh_CN.pm 9 lib/Geo/Direction/Name/Locale/zh_TW.pm 10 lib/Geo/Direction/Name/Spec.pm 8 11 Makefile.PL 9 12 MANIFEST This list of files 13 META.yml 10 14 README 11 15 t/00.load.t … … 13 17 t/01-2.ja_string.t 14 18 t/01-3.ko_string.t 19 t/01-4.zh_CN_string.t 20 t/01-5.zh_TW_string.t 15 21 t/02-1.en_dir.t 16 22 t/02-2.ja_dir.t 17 23 t/02-3.ko_dir.t 24 t/02-4.zh_CN_dir.t 25 t/02-5.zh_TW_dir.t 18 26 t/03.error.t 19 META.yml -
lang/perl/Geo-Direction-Name/trunk/lib/Geo/Direction/Name.pm
r21013 r31677 5 5 use Carp; 6 6 7 use version; our $VERSION = qv('0.0. 3');7 use version; our $VERSION = qv('0.0.4'); 8 8 use Scalar::Util qw(looks_like_number); 9 9 use Class::Inspector; … … 19 19 20 20 sub new { 21 my $class = shift; 22 my $locale = shift || "en_US"; 21 my ( $class, $opt ) = @_; 23 22 24 23 my $self = bless {}, $class; 25 24 26 $self->locale($locale); 25 my $spec; 26 my $locale; 27 if ( $opt && ref($opt) ) { 28 $spec = $opt->{spec}; 29 $locale = $opt->{locale}; 30 } else { 31 # For backward compatibility 32 $locale = $opt; 33 } 34 35 $self->spec( $spec ); 36 $self->locale( $locale ); 27 37 28 38 $self; 29 39 } 30 40 41 sub spec { 42 my $self = shift; 43 my $spec = shift; 44 my $noerr = shift; 45 my $errstr = "Specification class(subclass of Geo::Direction::Name::Spec) must be set"; 46 $spec ||= 'default' unless ( $self->{spec} ); 47 48 if ( $spec ) { 49 $errstr = "Geo::Direction::Name not support this specification now: " . $spec; 50 delete $self->{spec}; 51 my $class = __PACKAGE__ . '::Spec' . ( $spec eq 'default' ? '' : '::' . ucfirst($spec) ) ; 52 if( Class::Inspector->loaded($class) || $class->require ) { 53 $self->{spec} = $class->new; 54 } 55 } 56 57 croak $errstr unless ( $noerr || $self->{spec} ); 58 $self->{spec}; 59 } 60 31 61 sub locale { 32 my $self = shift; 33 if ($_[0]) { 34 my $locale = Geo::Direction::Name->load($_[0]); 35 36 croak("Geo::Direction::Name not support this locale now: " . $_[0]) unless ($locale); 37 38 $self->{locale} = $locale; 39 } 40 41 $self->{locale}; 62 my $self = shift; 63 64 $self->spec->locale( @_ ); 42 65 } 43 66 44 67 sub to_string { 45 68 my $self = shift; 46 my $direction = shift; 47 my $option = shift || {}; 48 49 my $abbr = defined($option->{abbreviation}) ? $option->{abbreviation} : 1; 50 my $devide = $option->{devide} || 8; 51 52 croak ("Direction value must be a number") unless (looks_like_number($direction)); 53 croak ("Abbreviation parameter must be 0 or 1") if ( $abbr !~ /^[01]$/ ); 54 my $log2 = log($devide)/log(2); 55 croak ("Devide parameter must be 4, 8, 16 or 32") if ( $log2 !~ /^[2345]$/ ); 56 57 $direction += 180 / $devide; 58 59 while ($direction < 0.0 || $direction >= 360.0) { 60 $direction += $direction < 0 ? 360.0 : -360.0; 61 } 62 63 my $i = int($direction * $devide / 360) * (32 / $devide); 64 65 $self->locale->string($i,$abbr); 69 70 $self->spec->to_string( @_ ); 66 71 } 67 72 68 73 sub from_string { 69 74 my $self = shift; 70 my $string = shift; 71 72 $self->locale->direction($string); 73 } 74 75 sub load { 76 my $class = shift; 77 my $locale = shift; 78 79 ($locale) = split(/\./,$locale); 80 my ($lang) = split(/_/,$locale); 81 82 foreach my $class (map { "Geo::Direction::Name::Locale::" . $_ } ($locale, $lang)) { 83 if( Class::Inspector->loaded($class) || $class->require) { 84 return $class->new; 85 } 86 } 87 return; 88 } 75 76 $self->spec->from_string( @_ ); 77 } 78 89 79 90 80 1; # Magic true value required at end of module … … 151 141 =item * new( [LOCALE] ) 152 142 143 Old interface (Backward compatible). 153 144 Return the Geo::Direction::Name object. 154 145 LOCALE is optional, default is "en_US". 146 147 =item * new( [OPTION] ) 148 149 New interface. 150 OPTION is hash reference, could be set two values. 151 Default specification is used. 152 153 =over 8 154 155 =item * spec 156 157 Set original spec name if want. 158 If not set, use default specification. 159 160 =item * locale 161 162 Set locale. 163 164 =back 155 165 156 166 =back … … 179 189 Default is 8. 180 190 191 After version 0.0.4, you can set other deviding number by using non-default specification. 192 193 181 194 =back 182 195 … … 191 204 192 205 =over 4 206 207 =item * spec 193 208 194 209 =item * locale -
lang/perl/Geo-Direction-Name/trunk/lib/Geo/Direction/Name/Locale.pm
r18518 r31677 5 5 use Carp; 6 6 7 use version; our $VERSION = qv('0.0. 2');7 use version; our $VERSION = qv('0.0.4'); 8 8 9 9 BEGIN … … 16 16 17 17 sub new { 18 my $class = shift; 18 my $class = shift; 19 my $dev = shift || 32; 19 20 20 21 my $dir = $class->dir_string(); 21 22 my $abbr = $class->abbr_string(); 22 23 24 my $dev1 = $dev - 1; 23 25 my %dirs = (); 24 26 my @strs = map { … … 26 28 $dirs{lc($abbr->[$_])} = $_; 27 29 [ $dir->[$_], $abbr->[$_],] 28 } (0.. 31);30 } (0..$dev1); 29 31 30 32 bless { 31 33 dirs => \%dirs, 32 34 strs => \@strs, 35 dev => $dev, 33 36 }, $class; 34 37 } … … 47 50 my $i = $self->{dirs}->{lc($str)}; 48 51 return unless (defined($i)); 49 return $i * 11.25;52 return $i * 360.0 / $self->{dev}; 50 53 } 51 54 -
lang/perl/Geo-Direction-Name/trunk/lib/Geo/Direction/Name/Locale/ja.pm
r18518 r31677 44 44 '西微北', 45 45 '西北西', 46 '北西微西', 47 '北西', 46 48 '北西微北', 47 '北西',48 '北西微西',49 49 '北北西', 50 50 '北微西', -
lang/perl/Geo-Direction-Name/trunk/t/01-2.ja_string.t
r7217 r31677 807 807 32 808 808 --- expected 809 北西微西 810 811 === 812 --- input 813 315.000 814 4 815 --- expected 816 北 817 818 === 819 --- input 820 315.000 821 8 822 --- expected 823 北西 824 825 === 826 --- input 827 315.000 828 16 829 --- expected 830 北西 831 832 === 833 --- input 834 315.000 835 32 836 --- expected 837 北西 838 839 === 840 --- input 841 326.250 842 4 843 --- expected 844 北 845 846 === 847 --- input 848 326.250 849 8 850 --- expected 851 北西 852 853 === 854 --- input 855 326.250 856 16 857 --- expected 858 北北西 859 860 === 861 --- input 862 326.250 863 32 864 --- expected 809 865 北西微北 810 866 811 867 === 812 868 --- input 813 315.000 814 4 815 --- expected 816 北 817 818 === 819 --- input 820 315.000 821 8 822 --- expected 823 北西 824 825 === 826 --- input 827 315.000 828 16 829 --- expected 830 北西 831 832 === 833 --- input 834 315.000 835 32 836 --- expected 837 北西 838 839 === 840 --- input 841 326.250 842 4 843 --- expected 844 北 845 846 === 847 --- input 848 326.250 849 8 850 --- expected 851 北西 852 853 === 854 --- input 855 326.250 869 337.500 870 4 871 --- expected 872 北 873 874 === 875 --- input 876 337.500 877 8 878 --- expected 879 北 880 881 === 882 --- input 883 337.500 856 884 16 857 885 --- expected … … 860 888 === 861 889 --- input 862 326.250863 32864 --- expected865 北西微西866 867 ===868 --- input869 890 337.500 870 4 871 --- expected 872 北 873 874 === 875 --- input 876 337.500 877 8 878 --- expected 879 北 880 881 === 882 --- input 883 337.500 884 16 891 32 885 892 --- expected 886 893 北北西 … … 888 895 === 889 896 --- input 890 337.500891 32892 --- expected893 北北西894 895 ===896 --- input897 897 348.750 898 898 4 -
lang/perl/Geo-Direction-Name/trunk/t/02-2.ja_dir.t
r7217 r31677 188 188 === 189 189 --- input 190 北西微西 191 --- expected 192 303.750 193 194 === 195 --- input 196 北西 197 --- expected 198 315.000 199 200 === 201 --- input 190 202 北西微北 191 203 --- expected 192 303.750193 194 ===195 --- input196 北西197 --- expected198 315.000199 200 ===201 --- input202 北西微西203 --- expected204 204 326.250 205 205 -
lang/perl/Geo-Direction-Name/trunk/t/03.error.t
r21013 r31677 6 6 7 7 eval { Geo::Direction::Name->new("bb_BB"); }; 8 ok $@ =~ /Geo::Direction::Name not support this locale now: bb_BB/;8 ok $@ =~ /Geo::Direction::Name::Spec not support this locale now: bb_BB/; 9 9 10 10 my $dobj = Geo::Direction::Name->new; … … 17 17 18 18 eval { $dobj->to_string(180.0,{devide => 5}); }; 19 ok $@ =~ /Devide parameter must be 4, 8, 16 or32/;19 ok $@ =~ /Devide parameter must be 4,8,16,32/; 20 20 21 21 is $dobj->from_string("foo"), undef;
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)