Zoffix Znet > WWW-Google-Time-0.0119 > WWW::Google::Time

Download:
WWW-Google-Time-0.0119.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 0.0119   Source  

NAME ^

WWW::Google::Time - get time for various locations via Google

SYNOPSIS ^

    use strict;
    use warnings;

    use WWW::Google::Time;

    my $t = WWW::Google::Time->new;

    $t->get_time("Toronto")
        or die $t->error;

    printf "It is %s, %s (%s) in %s\n",
        @{ $t->data }{ qw/day_of_week  time  time_zone  where/ };

DESCRIPTION ^

Module is very simple, it takes a name of some place and returns the current time in that place (as long as Google has that information).

CONSTRUCTOR ^

new

    my $t = WWW::Google::Time->new;

    my $t = WWW::Google::Time->new(
        ua => LWP::UserAgent->new( agent => "Mozilla", timeout => 30 )
    );

Creates and returns a new WWW::Google::Time object. So far takes one key/value pair argument - ua. The value of the ua argument must be an object akin to LWP::UserAgent which has a get() method that returns an HTTP::Response object. The default object for the ua argument is LWP::UserAgent->new( agent => "Mozilla", timeout => 30 )

METHODS ^

get_time

    $t->get_time('Toronto')
        or die $t->error;

Instructs the object to fetch time information for the given location. Takes one mandatory argument which is a name of the place for which you want to obtain time data. On failure returns either undef or an empty list, depending on the context, and the reason for failure can be obtained via error() method. On success returns a hashref with the following keys/values:

    $VAR1 = {
          'time' => '7:00am',
          'time_zone' => 'EDT',
          'day_of_week' => 'Saturday',
          'where' => 'Toronto, Ontario'
    };

time

    'time' => '7:00am',

The time key contains the time for the location as a string.

time_zone

    'time_zone' => 'EDT',

The time_zone key contains the time zone in which the given location is.

day_of_week

    'day_of_week' => 'Saturday',

The day_of_week key contains the day of the week that is right now in the location given.

where

    'where' => 'Toronto, Ontario'

The where key contains the name of the location to which the keys described above correlate. This is basically how Google interpreted the argument you gave to get_time() method.

data

    $t->get_time('Toronto')
        or die $t->error;

    my $time_data = $t->data;

Must be called after a successful call to get_time(). Takes no arguments. Returns the exact same hashref the last call to get_time() returned.

where

    $t->get_time('Toronto')
        or die $t->error;

    print $t->where; # prints 'Toronto'

Takes no arguments. Returns the argument passed to the last call to get_time().

error

    $t->get_time("Some place that doesn't exist")
        or die $t->error;
    ### dies with "Could not find time data for that location"

When get_time() fails (by returning either undef or empty list) the reason for failure will be available via error() method. The "falure" is both, not being able to find time data for the given location or network errors. The error message will say which one it is.

ua

    my $ua = $t->ua;
    $ua->proxy('http', 'http://foobarbaz.com');

    $t->ua( LWP::UserAgent->new( agent => 'Mozilla' ) );

Takes one optional argument which must fit the same criteria as the ua argument to the contructor (new() method). Returns the object currently beign used for accessing Google.

EXAMPLES ^

The examples/ directory of this distribution contains an executable script that uses this module.

TO DO ^

Sometimes Google returns multiple times.. e.g. "time in Norway" returns three results. Would be nice to be able to return all three results in an arrayref or something

AUTHOR ^

Zoffix Znet, <zoffix at cpan.org> (http://zoffix.com/, http://haslayout.net/, http://zofdesign.com/)

Patches by Neil Stott and Zach Hauri (http://zach.livejournal.com/)

BUGS ^

Please report any bugs or feature requests to bug-www-google-time at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Google-Time. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT ^

You can find documentation for this module with the perldoc command.

    perldoc WWW::Google::Time

You can also look for information at:

COPYRIGHT & LICENSE ^

Copyright 2008 Zoffix Znet, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

syntax highlighting: