zeroclickinfo-goodies/lib/DDG/Goodie/Parcelforce.pm

44 lines
1.7 KiB
Perl
Raw Normal View History

package DDG::Goodie::Parcelforce;
2014-03-26 14:50:51 -07:00
use DDG::Goodie;
2014-03-26 15:07:24 -07:00
zci is_cached => 1;
zci answer_type => "parcelforce";
2014-03-26 14:50:51 -07:00
primary_example_queries 'royal mail RU401513974GB';
secondary_example_queries 'track parcelforce PBTM8237263001';
description 'Track a Parcelforce / Royal Mail parcel';
icon_url "/i/www.parcelforce.com.ico";
name 'Parcelforce';
2014-03-26 15:07:24 -07:00
code_url
'https://github.com/duckduckgo/zeroclickinfo-goodies/blob/master/lib/DDG/Goodie/Parcelforce.pm';
2014-03-26 14:50:51 -07:00
category 'ids';
topics 'special_interest';
2014-03-26 15:07:24 -07:00
attribution
github => [ 'https://github.com/TopHattedCoder', 'Tom Bebbington' ],
twitter => [ 'http://twitter.com/TopHattedCoder', 'TopHattedCoder' ];
2014-03-26 14:50:51 -07:00
# Regex for parcelforce / royal mail
2014-03-26 14:50:51 -07:00
my $rm_qr = qr/royalmail|parcelforce/io;
my $tracking_qr = qr/package|parcel|track(?:ing|)|num(?:ber|)|\#/i;
2014-03-26 15:07:24 -07:00
2014-03-26 14:50:51 -07:00
# note: parcelforce format listed at http://www.parcelforce.com/help-information/frequently-asked-questions/track-parcel#2
2014-03-26 15:07:24 -07:00
my $parcel
= qr/[A-Z]{2}[0-9]{7}|[A-Z]{4}[0-9]{10}|[A-Z]{2}[0-9]{9}GB|[0-9]{12}|[A-Z]{2}[0-9]{9}[A-Z]{2}/i;
2014-03-26 14:50:51 -07:00
triggers query_nowhitespace_nodash => qr/
^$rm_qr.*?(?<parcel_number>$parcel)$|
^(?<parcel_number>$parcel).*?$rm_qr$|
^(?:$tracking_qr|$rm_qr|)*(?<parcel_number>$parcel)(?:$tracking_qr|$rm_qr|)*$
/xo;
handle query_nowhitespace_nodash => sub {
my $parcel_number = $+{parcel_number};
2014-03-26 15:07:24 -07:00
return $parcel_number,
heading => 'Parcelforce Tracking',
2014-03-26 15:07:24 -07:00
html =>
qq(Track this parcel at <a href="http://www.parcelforce.com/track-trace?trackNumber=$parcel_number">Parcelforce</a>.);
2014-03-26 14:50:51 -07:00
};
1;