<<

TITLE

QFCParser

AUTHOR

paramsan

NAME

Concrete implementation of an AbstractParser class specifically for the QFC store. This documentation is for internal use only on how to deal with the QFCParser objects.

SYNOPSIS

        use QFCParser;
        $qfcParser = QFCParser->new();
        $allSpecials = $qfcParser->GetSpecials($zipCode);

REQUIRES

Perl5.10.0, WWW::Mechanize, HTTP::Cookies, AbstractParser

EXPORTS

Nothing

DESCRIPTION

This class specifically implements the GetSpecials() method of the AbstractParser. As such, Directly constructing this class is not recommended. Please see AbstractParserFactory on how to construct instances of concrete AbstractParser(s).

CLASS VARIABLES

See "CLASS VARIABLES" in AbstractParser for the different class variables that can also be used here.

new

Description

The default constructor for constructing QFCParser object.

Arguments

None

Returns

Returns a reference to a new QFCParser object.

Usage

$qfcParser = QFCParser->new();

GetSpecials

Description

Provides implementation for the abstract method of the AbstractParser class. See "GetSpecials" in AbstractParser for more information.

Arguments

$zipCode: Zipcode for which to retrieve the specials for.

Returns

A reference to an array of Specials in the following format,

[ [ItemName, ItemPrice], [ItemName, ItemPrice] ... ];

Usage

$specialRef = $qfcParser->GetSpecials();

INTERNAL METHODS

QFC_GetSpecialsForZipCode

Description

Actual method that does the whole work of getting the QFC specials for a certain zip code. The store that is chosen is the closest one to a certain zip code.

Arguments

$zipCode: Zipcode for which to retrieve the specials for.

Returns

A reference to an array of Specials in the following format,

[ [ItemName, ItemPrice], [ItemName, ItemPrice] ... ];

This method will call die() with pertinant error message if anything goes wrong during the parsing of the QFC webpage.

Usage

$specialRef = $self->QFC_GetSpecialsForZipCode();

AssertTagValid

Description

Assert if the tag passed in is NOT undef

Arguments

$tag: The tag to check undef for $atLine: Set this to __LINE__, there for convenient debugging to know at what line the tag was undef (and hence can be helpful for finding errors in parsing).

Returns

Nothing

This method will die() with pertinent error message displaying the line number (if passed in) if the tag is undefined.

Usage

$self->AssertTagValid($mech->get_tag("a"), __LINE__);

CheckTagValue

Description

Another helper method to make sure the value of the tag matches what is expected.

Arguments

$actualValue: The actual value of the tag. $expectedTagValue: The expected value of the tag, can be a regex string $atLine: The line number where this method is called. Recommended to be __LINE__.

Returns

Nothing

This method will die() with pertinent error message displaying the line number if $actualValue does not match $expectedTagValue.

Usage

For example to assert that the returned text is all numbers:

$self->CheckTagValue($mech->get_trimmed_text("/a"), "\d+", __LINE__);

WriteContentToFile

Description

A handly method used as a debugging tool to write the html to a file that is returned during parsing of the specials at different steps.

Arguments

$mech: Reference to the Mechanized object. $fileName: The file to output the html content to.

Returns

Nothing.

This method will warn() the users if filename cannot be opened.

Usage

$self->WriteContentToFile($mech, "weekly_specials.hmlt");

<<