Show
Ignore:
Timestamp:
12/06/07 18:55:16 (7 years ago)
Author:
clouder
Message:

lang/perl/HTTP-MobileAgent?-Plugin-Locator: modifiled to apply Apache::Request and CGI instance, and return G::C::C::Point instance

Location:
lang/perl/HTTP-MobileAgent-Plugin-Locator/trunk
Files:
11 added
12 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/HTTP-MobileAgent-Plugin-Locator/trunk/Build.PL

    r2437 r2652  
    66    module_name         => 'HTTP::MobileAgent::Plugin::Locator', 
    77    license             => '', 
    8     dist_author         => 'Yoshiki Kurihara <kurihara@cpan.org>', 
     8    dist_author         => 'Yoshiki Kurihara <kurihara at cpan.org>', 
    99    dist_version_from   => 'lib/HTTP/MobileAgent/Plugin/Locator.pm', 
    1010    requires => { 
    1111        'Test::More' => 0, 
     12        'Geo::Coordinates::Converter' => 0, 
     13        'Location::Area::DoCoMo::iArea' => 0, 
     14        'HTTP::MobileAgent' => 0, 
     15        'UNIVERSAL::require' => 0, 
     16        'UNIVERSAL::can' => 0, 
    1217    }, 
    1318    add_to_cleanup      => [ 'HTTP-MobileAgent-Plugin-Locator-*' ], 
  • lang/perl/HTTP-MobileAgent-Plugin-Locator/trunk/META.yml

    r2437 r2652  
    1515  HTTP::MobileAgent: 0 
    1616  Location::Area::DoCoMo::iArea: 0 
     17  UNIVERSAL::can: 0 
    1718  UNIVERSAL::require: 0 
    1819version: 0.01 
  • lang/perl/HTTP-MobileAgent-Plugin-Locator/trunk/Makefile.PL

    r2437 r2652  
    1414requires 'HTTP::MobileAgent' => 0; 
    1515requires 'UNIVERSAL::require' => 0; 
     16requires 'UNIVERSAL::can' => 0; 
    1617 
    1718auto_install; 
  • lang/perl/HTTP-MobileAgent-Plugin-Locator/trunk/lib/HTTP/MobileAgent/Plugin/Locator.pm

    r2437 r2652  
    44use strict; 
    55use HTTP::MobileAgent; 
     6use Carp; 
    67use UNIVERSAL::require; 
     8use UNIVERSAL::can; 
    79 
    810our $VERSION = '0.01'; 
     
    1214    no strict 'refs'; 
    1315    *{"HTTP\::MobileAgent\::gps_compliant"} = \&_gps_compliant; 
    14     *{"HTTP\::MobileAgent\::get_location"}  = \&_get_location; 
     16    *{"HTTP\::MobileAgent\::locator"}       = sub { $class->new( shift ) }; 
     17    *{"HTTP\::MobileAgent\::get_location"}  = sub { 
     18        my ( $self, $stuff ) = @_; 
     19        $self->locator->get_location( _prepare_params( $stuff ) ); 
     20    }; 
    1521} 
    1622 
     
    2733} 
    2834 
    29 sub _get_location { 
    30     my ( $self, $query ) = @_; 
    31     my $module; 
    32     if ( $self->is_docomo ) { 
    33         $module = $self->gps_compliant 
    34             ? 'HTTP::MobileAgent::Plugin::Locator::DoCoMo::GPS' 
    35             : 'HTTP::MobileAgent::Plugin::Locator::DoCoMo::BasicLocation'; 
     35sub new { 
     36    my ( $class, $agent ) = @_; 
     37 
     38    my $sub; 
     39    if ( $agent->is_docomo ) { 
     40        $sub = $agent->gps_compliant ? 'DoCoMo::GPS' 
     41                                     : 'DoCoMo::BasicLocation'; 
    3642    } 
    37     elsif ( $self->is_ezweb ) { 
    38         $module = $self->gps_compliant 
    39             ? 'HTTP::MobileAgent::Plugin::Locator::EZweb::GPS' 
    40             : 'HTTP::MobileAgent::Plugin::Locator::EZweb::BasicLocation'; 
     43    elsif ( $agent->is_ezweb ) { 
     44        $sub = $agent->gps_compliant ? 'EZweb::GPS' 
     45                                     : 'EZweb::BasicLocation'; 
    4146    } 
    42     elsif ( $self->is_softbank ) { 
    43         $module = $self->gps_compliant 
    44             ? 'HTTP::MobileAgent::Plugin::Locator::SoftBank::GPS' 
    45             : 'HTTP::MobileAgent::Plugin::Locator::SoftBank::BasicLocation'; 
     47    elsif ( $agent->is_softbank ) { 
     48        $sub = $agent->gps_compliant ? 'SoftBank::GPS' 
     49                                     : 'SoftBank::BasicLocation'; 
    4650    } 
    47     elsif ( $self->is_airh_phone ) { 
    48         $module = 'HTTP::MobileAgent::Plugin::Locator::Willcom::BasicLocation'; 
     51    elsif ( $agent->is_airh_phone ) { 
     52        $sub = 'Willcom::BasicLocation'; 
    4953    } 
    5054    else { 
    51         die "non mobile"; 
     55        croak( "Invalid mobile user agent: " . $agent->user_agent ); 
    5256    } 
    53     $module->require or die $!; 
    54     return $module->new( $query )->get_location; 
     57 
     58    my $locator_class = "HTTP::MobileAgent::Plugin::Locator\::$sub"; 
     59    $locator_class->require or die $!; 
     60    return bless {}, $locator_class; 
     61} 
     62 
     63sub get_location { die "ABSTRACT METHOD" } 
     64 
     65sub _prepare_params { 
     66    my $stuff = shift; 
     67    if ( ref $stuff && eval { $stuff->can( 'param' ) } ) { 
     68        return +{ map { $_ => $stuff->param( $_ ) } $stuff->param }; 
     69    } 
     70    else { 
     71        return $stuff; 
     72    } 
    5573} 
    5674 
     
    6482=head1 SYNOPSIS 
    6583 
     84    use CGI; 
    6685    use HTTP::MobileAgent; 
    6786    use HTTP::MobileAgent::Plugin::Locator; 
    6887 
    69     # get parameters 
     88    # get location is Geo::Coordinates::Converter::Point instance formatted wgs84 
    7089    my $q = CGI->new; 
    71     $params = { map { $_ => $q->param( $_ ) } $q->param }; 
     90    my $agent = HTTP::MobileAgent->new; 
     91    my $location = $agent->location( $q ); 
    7292 
    73     # get location 
    74     my $agent = HTTP::MobileAgent->new; 
    75     my $location = $agent->get_location( $params ); 
    76  
    77     print "lat is " . $location->{ lat }; 
    78     print "lng is " . $location->{ lng }; 
     93    print "lat is " . $location->lat; 
     94    print "lng is " . $location->lng; 
    7995 
    8096=head1 METHODS 
     
    8298=over 
    8399 
    84 =item get_location([ gps or basic location parameters from carrier ]); 
     100=item location([params]); 
    85101 
    86 return hashref included latitude and longitude if specify gps or basic location parameters from carrier. The parameters is different by carrier. 
     102return Geo::Coordinates::Converter::Point instance formatted if specify gps or basic location parameters sent from carrier. The parameters are different by each carrier. 
    87103 
    88 =item gps_compliant 
     104This method accept a Apache instance, CGI instance or hashref of query parameters. 
    89105 
    90 returns if the agent is GPS compliant 
     106=item gps_compliant() 
     107 
     108returns if the agent is GPS compliant. 
    91109 
    92110=back 
     
    126144=back 
    127145 
     146=head1 EXAMPLES 
     147 
     148There is request template using C<Template> in eg directory and mod_rewrite configuration for ezweb extraordinary parameter handling. 
     149 
     150=head1 SEE ALSO 
     151 
     152C<HTTP::MobileAgent>, C<Geo::Coordinates::Converter>, C<Geo::Coordinates::Converter::Point>, C<Location::Area::DoCoMo::iArea> 
     153 
    128154=head1 AUTHOR 
    129155 
  • lang/perl/HTTP-MobileAgent-Plugin-Locator/trunk/lib/HTTP/MobileAgent/Plugin/Locator/Base.pm

    r2437 r2652  
    66__PACKAGE__->mk_accessors( qw( params ) ); 
    77 
    8 sub new { 
    9     my ( $class, $stuff ) = @_; 
    10     if ( UNIVERSAL::isa( $stuff, 'Apache' ) ) { 
    11         my $req = Apache::Request->new( $stuff ); 
    12         bless { params => { 
    13             map { $_ => $req->param( $_ ) } $req->param 
    14         } }, $class; 
    15     } 
    16     else { 
    17         bless { params => $stuff }, $class; 
    18     } 
    19 } 
    20  
    2181; 
  • lang/perl/HTTP-MobileAgent-Plugin-Locator/trunk/lib/HTTP/MobileAgent/Plugin/Locator/DoCoMo/BasicLocation.pm

    r2437 r2652  
    33 
    44use strict; 
    5 use base qw( HTTP::MobileAgent::Plugin::Locator::Base ); 
     5use base qw( HTTP::MobileAgent::Plugin::Locator ); 
    66use Location::Area::DoCoMo::iArea; 
     7use Geo::Coordinates::Converter; 
    78 
    89sub get_location { 
    9     my $self = shift; 
    10     my $areacode = $self->params->{ AREACODE }; 
     10    my ( $self, $params ) = @_; 
     11    my $areacode = $params->{ AREACODE }; 
    1112    my $obj = Location::Area::DoCoMo::iArea->create_iarea( $areacode ); 
    12     my ( $lat, $lng ) = $obj->get_center->datum_tokyo->format_gpsone->array; 
    13     return +{ 
    14         lat => $lat || undef, 
    15         lng => $lng || undef, 
    16     }; 
     13    my ( $lat, $lng ) = $obj->get_center->datum_wgs84->format_gpsone->array; 
     14    return Geo::Coordinates::Converter->new( 
     15        lat    => $lat || undef, 
     16        lng    => $lng || undef, 
     17        datum  => 'wgs84', 
     18    )->convert; 
    1719} 
    1820 
  • lang/perl/HTTP-MobileAgent-Plugin-Locator/trunk/lib/HTTP/MobileAgent/Plugin/Locator/DoCoMo/GPS.pm

    r2437 r2652  
    33 
    44use strict; 
    5 use base qw( HTTP::MobileAgent::Plugin::Locator::Base ); 
     5use base qw( HTTP::MobileAgent::Plugin::Locator ); 
    66use Geo::Coordinates::Converter; 
    77 
    88sub get_location { 
    9     my $self = shift; 
    10     my $lat   = $self->params->{ lat }; 
    11     my $lng   = $self->params->{ lon }; 
    12     my $datum = $self->params->{ geo }; 
    13     my $geo = Geo::Coordinates::Converter->new( 
     9    my ( $self, $params ) = @_; 
     10    my $lat   = $params->{ lat }; 
     11    my $lng   = $params->{ lon }; 
     12    my $datum = $params->{ geo }; 
     13    return Geo::Coordinates::Converter->new( 
    1414        lat   => $lat, 
    1515        lng   => $lng, 
    1616        datum => lc $datum, 
    17     )->convert( 'tokyo' ); 
    18     return +{ 
    19         lat => $geo->lat || undef, 
    20         lng => $geo->lng || undef, 
    21     }; 
     17    )->convert( 'wgs84' ); 
    2218} 
    2319 
  • lang/perl/HTTP-MobileAgent-Plugin-Locator/trunk/lib/HTTP/MobileAgent/Plugin/Locator/EZweb/BasicLocation.pm

    r2437 r2652  
    11package HTTP::MobileAgent::Plugin::Locator::EZweb::BasicLocation; 
    2 # 簡易位置情報 
     2# Simple Location Information 
    33 
    44use strict; 
    5 use base qw( HTTP::MobileAgent::Plugin::Locator::Base ); 
     5use base qw( HTTP::MobileAgent::Plugin::Locator ); 
    66use Geo::Coordinates::Converter; 
    77 
    88sub get_location { 
    9     my $self = shift; 
    10     my $lat   = $self->params->{ lat }; 
    11     my $lng   = $self->params->{ lon }; 
    12     my $datum = 'wgs84'; 
    13     my $geo   = Geo::Coordinates::Converter->new( 
    14         lat   => $lat, 
    15         lng   => $lng, 
    16         datum => $datum, 
    17     )->convert( 'tokyo' ); 
    18     return +{ 
    19         lat => $geo->lat || undef, 
    20         lng => $geo->lng || undef, 
    21     }; 
     9    my ( $self, $params ) = @_; 
     10    my $lat = $params->{ lat }; 
     11    my $lng = $params->{ lon }; 
     12    my $datum = $params->{ datum } || 'wgs84'; 
     13    my $format = $params->{ unit } || 'dms'; 
     14    return Geo::Coordinates::Converter->new( 
     15        lat    => $lat, 
     16        lng    => $lng, 
     17        datum  => $datum, 
     18        format => $format || undef, 
     19    )->convert; 
    2220} 
    2321 
  • lang/perl/HTTP-MobileAgent-Plugin-Locator/trunk/lib/HTTP/MobileAgent/Plugin/Locator/EZweb/GPS.pm

    r2437 r2652  
    33 
    44use strict; 
    5 use base qw( HTTP::MobileAgent::Plugin::Locator::Base ); 
     5use base qw( HTTP::MobileAgent::Plugin::Locator ); 
    66use Geo::Coordinates::Converter; 
    77 
    88sub get_location { 
    9     my $self = shift; 
    10     (my $lat = $self->params->{ lat }) =~ s/^[\-\+]//g; 
    11     (my $lng = $self->params->{ lon }) =~ s/^[\-\+]//g; 
    12     my $datum = $self->params->{ datum } || 'tokyo'; 
    13     my $geo = Geo::Coordinates::Converter->new( 
    14         lat   => $lat, 
    15         lng   => $lng, 
    16         datum => $datum, 
    17     )->convert( 'tokyo' ); 
    18     return +{ 
    19         lat => $geo->lat || undef, 
    20         lng => $geo->lng || undef, 
    21     }; 
     9    my ( $self, $params ) = @_; 
     10    (my $lat = $params->{ lat }) =~ s/^[\-\+]//g; 
     11    (my $lng = $params->{ lon }) =~ s/^[\-\+]//g; 
     12    my $datum = defined $params->{ datum } && $params->{ datum } == 1 ? 'tokyo' : 'wgs84'; 
     13    my $format = defined $params->{ unit } && $params->{unit} == 1 ? 'degree' : 'dms'; 
     14    return Geo::Coordinates::Converter->new( 
     15        lat    => $lat, 
     16        lng    => $lng, 
     17        datum  => $datum, 
     18        format => $format, 
     19    )->convert( 'wgs84' ); 
    2220} 
    2321 
  • lang/perl/HTTP-MobileAgent-Plugin-Locator/trunk/lib/HTTP/MobileAgent/Plugin/Locator/SoftBank/BasicLocation.pm

    r2437 r2652  
    11package HTTP::MobileAgent::Plugin::Locator::SoftBank::BasicLocation; 
    2 # 簡易位置情報 
     2# Simple Location Information 
    33 
    44use strict; 
    5 use base qw( HTTP::MobileAgent::Plugin::Locator::Base ); 
     5use base qw( HTTP::MobileAgent::Plugin::Locator ); 
     6use Geo::Coordinates::Converter; 
    67 
    78sub get_location { 
    8     my ( $self, $page ) = @_; 
     9    my $self = shift; 
    910    my $geocode = $ENV{ HTTP_X_JPHONE_GEOCODE }; 
    1011    $geocode =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; 
    1112    my ( $lat, $lng, $address ) = split /\x1a/, $geocode; 
    12     return +{ 
    13         lat => _convert_point( $lat ) || undef, 
    14         lng => _convert_point( $lng ) || undef, 
    15     }; 
     13    return Geo::Coordinates::Converter->new( 
     14        lat   => _convert_point( $lat ) || undef, 
     15        lng   => _convert_point( $lng ) || undef, 
     16        datum => 'tokyo', 
     17    )->convert( 'wgs84' ); 
    1618} 
    1719 
  • lang/perl/HTTP-MobileAgent-Plugin-Locator/trunk/lib/HTTP/MobileAgent/Plugin/Locator/SoftBank/GPS.pm

    r2437 r2652  
    33 
    44use strict; 
    5 use base qw( HTTP::MobileAgent::Plugin::Locator::Base ); 
     5use base qw( HTTP::MobileAgent::Plugin::Locator ); 
    66use Geo::Coordinates::Converter; 
    77 
    88sub get_location { 
    9     my $self = shift; 
    10     my ( $lat, $lng ) = $self->params->{ pos } =~ /^[NS]([\d\.]+)[EW]([\d\.]+)$/; 
    11     my $geo = Geo::Coordinates::Converter->new( 
     9    my ( $self, $params ) = @_; 
     10    my ( $lat, $lng ) = $params->{ pos } =~ /^[NS]([\d\.]+)[EW]([\d\.]+)$/; 
     11    my $datum = $params->{ geo } || 'wgs84'; 
     12    return Geo::Coordinates::Converter->new( 
    1213        lat   => $lat, 
    1314        lng   => $lng, 
    14         datum => 'wgs84', 
    15     )->convert( 'tokyo' ); 
    16     return +{ 
    17         lat => $geo->lat || undef, 
    18         lng => $geo->lng || undef, 
    19     }; 
     15        datum => $datum, 
     16    )->convert; 
    2017} 
    2118 
  • lang/perl/HTTP-MobileAgent-Plugin-Locator/trunk/lib/HTTP/MobileAgent/Plugin/Locator/Willcom/BasicLocation.pm

    r2437 r2652  
    22 
    33use strict; 
    4 use base qw( HTTP::MobileAgent::Plugin::Locator::Base ); 
     4use base qw( HTTP::MobileAgent::Plugin::Locator ); 
     5use Geo::Coordinates::Converter; 
    56 
    67sub get_location { 
    7     my $self = shift; 
    8     my ( $lat, $lng ) = $self->params->{ pos } =~ /^N([^E]+)E(.+)$/; 
    9     return +{ 
    10         lat => $lat || undef, 
    11         lng => $lng || undef, 
    12     }; 
     8    my ( $self, $params ) = @_; 
     9    my ( $lat, $lng ) = $params->{ pos } =~ /^N([^E]+)E(.+)$/; 
     10    return Geo::Coordinates::Converter->new( 
     11        lat   => $lat || undef, 
     12        lng   => $lng || undef, 
     13        datum => 'tokyo', 
     14    )->convert( 'wgs84' ); 
    1315} 
    1416