The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

WWW::Purolator::TrackingInfo - access Purolator's tracking information

SYNOPSIS

    use strict;
    use warnings;
    use WWW::Purolator::TrackingInfo;

    my $t = WWW::Purolator::TrackingInfo->new;

    my $info = $t->track('AJT1395053')
        or die "Error: " . $t->error;

    use Data::Dumper;
    print Dumper $info;

DESCRIPTION

This module probably does not provide fully blown functionality and is rather simple; it does only what I needed it to do for my project, contact me if you need more functionality.

The module accesses http://purolator.com/ and gets tracking information for the package from the given PIN (e.g. AJT1395053)

CONSTRUCTOR

    my $t = WWW::Purolator::TrackingInfo->new;

    my $t = WWW::Purolator::TrackingInfo->new(
        ua => LWP::UserAgent->new( agent => 'Opera 9.5', timeout => 30 ),
    );

Creates and returns a new WWW::Purolator::TrackingInfo object. Takes the following arguments:__PACKAGE__->mk_classaccessors qw/ error info ua

ua

    my $t = WWW::Purolator::TrackingInfo->new(
        ua => LWP::UserAgent->new( agent => 'Opera 9.5', timeout => 30 ),
    );

Optional. Specifies an LWP::UserAgent-like object to use for accessing Purolator's site. Note: since Purolator uses HTTPS, you'll most likely need to install Crypt::SSLeay or something along those lines. Technically, this object can be anything that has a get() method that functions exactly the same as the one present in LWP::UserAgent. Defaults to:

    LWP::UserAgent->new( agent => 'Opera 9.5', timeout => 30 )

METHODS/ACCESSORS

track

    my $info = $t->track('AJT1399063')
        or die $t->error;

Instructs the object to obtain transit information from Purolator using a PIN. Currently takes one mandatory argument: Purolator's PIN for the package. On failure (e.g. network error, or invalid PIN was specified) returns either undef or an empty list depending on the context and the reason for failure will be available via error() method. On success returns a hashref with the following keys/values (explained below this dump):

    $VAR1 = {
    'pin' => 'AJT1399063',
    'is_delivered' => 1,
    'html' => '
        <table>
        <thead class="TableHeader">
            <tr>
                <td id="date">Scan Date</td>
                <td id="time">Scan Time</td>
                <td id="status">Status</td>
                <td id="comment">Comment</td>
            </tr>
        </thead>
        <tbody class="TableData2">
            
            <tr><td>2009/09/16</td><td>10:23</td><td>Delivered to JODY at RECEPTION of ARTHUR BOOKS at 192 WELLINGTON ST. EAST P6A2L0 via SAULT STE. MARIE, ON depot</td><td></td></tr>
            
            <tr><td>2009/09/16</td><td>09:45</td><td>On vehicle for delivery via SAULT STE. MARIE, ON depot</td><td></td></tr>
            
            <tr><td>2009/09/15</td><td>16:45</td><td>Picked up by Purolator via TORONTO SORT CTR/CTR TRIE, ON depot</td><td></td></tr>
            
        </tbody>
        </table>
        ',
    'details' => [
             {
               'comment' => undef,
               'status' => 'Delivered to JODY at RECEPTION of ARTHUR BOOKS at 192 WELLINGTON ST. EAST P6A2L0 via SAULT STE. MARIE, ON depot',
               'scan_time' => '10:23',
               'scan_date' => '2009/09/16'
             },
             {
               'comment' => undef,
               'status' => 'On vehicle for delivery via SAULT STE. MARIE, ON depot',
               'scan_time' => '09:45',
               'scan_date' => '2009/09/16'
             },
             {
               'comment' => undef,
               'status' => 'Picked up by Purolator via TORONTO SORT CTR/CTR TRIE, ON depot',
               'scan_time' => '16:45',
               'scan_date' => '2009/09/15'
             },
           ]
        };

pin

    print "This tracking info is for PIN: " . $t->info->{pin};

is_delivered

    $t->info->{is_delivered}
        and print "Package was delivered!";

If the package was delivered, then is_delivered key will be present and set to value 1.

html

    print $t->info->{html};

The html key will contain raw HTML of the tracking information table as it was displayed on Purolator's page; useful for displaying the info in a Web app.

details

    $t->info->{is_delivered}
        and print $t->info->{details}[0]{status};

The details key will contain an arrayref of hashrefs. Each of those hashrefs represents a line of tracking info (i.e. the row in the Purolator's tracking table). There are four keys in each of those hashrefs:

scan_date

    'scan_date' => '2009/09/10'

Specifies the date of the scan for the current entry. The format is the same as is displayed on Purolator's site.

scan_time

    'scan_time' => '17:52',

Specifies the time of the scan for the current entry. The format is the same as is displayed on Purolator's site.

status

    'status' => 'Shipment In Transit via TORONTO SORT CTR/CTR TRIE, ON depot',

Specifies the status of the package when the current entry was added.

comment

    'comment' => undef,

I never actually seen any comments there, but there is a column named "Comment" on Purolator's tracking table, so here it is. I assume these are for special comments in case of some trouble.

info

    my $last_track_info = $t->info;

Takes no arguments returns the same value last call to track() method returned. See track() method's description above for details.

error

    $t->track('AJT1399063')
        or die $t->error;

Takes no arguments. Returns a human readable reason for why track() method failed (if it did, of course).

ua

    my $current_ua = $t->ua;
    
    $t->ua(
        LWP::UserAgent->new( agent => 'Opera 9.5', timeout => 30 )
    );

Returns currently used LWP::UserAgent-like object (see ua constructor's argument). Takes one optional argument that is the new object to use.

AUTHOR

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

BUGS

Please report any bugs or feature requests to bug-www-purolator-trackinginfo at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=WWW-Purolator-TrackingInfo. 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::Purolator::TrackingInfo

You can also look for information at:

COPYRIGHT & LICENSE

Copyright 2009 'Zoffix, all rights reserved.

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