QFCParser
paramsan
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.
use QFCParser; $qfcParser = QFCParser->new(); $allSpecials = $qfcParser->GetSpecials($zipCode);
Perl5.10.0, WWW::Mechanize, HTTP::Cookies, AbstractParser
Nothing
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).
See "CLASS VARIABLES" in AbstractParser for the different class variables that can also be used here.
The default constructor for constructing QFCParser object.
None
Returns a reference to a new QFCParser object.
$qfcParser = QFCParser->new();
Provides implementation for the abstract method of the AbstractParser class. See "GetSpecials" in AbstractParser for more information.
$zipCode: Zipcode for which to retrieve the specials for.
A reference to an array of Specials in the following format,
[ [ItemName, ItemPrice], [ItemName, ItemPrice] ... ];
$specialRef = $qfcParser->GetSpecials();
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.
$zipCode: Zipcode for which to retrieve the specials for.
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.
$specialRef = $self->QFC_GetSpecialsForZipCode();
Assert if the tag passed in is NOT undef
$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).
Nothing
This method will die() with pertinent error message displaying the line number (if passed in) if the tag is undefined.
$self->AssertTagValid($mech->get_tag("a"), __LINE__);
Another helper method to make sure the value of the tag matches what is expected.
$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__.
Nothing
This method will die() with pertinent error message displaying the line number if $actualValue does not match $expectedTagValue.
For example to assert that the returned text is all numbers:
$self->CheckTagValue($mech->get_trimmed_text("/a"), "\d+", __LINE__);
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.
$mech: Reference to the Mechanized object. $fileName: The file to output the html content to.
Nothing.
This method will warn() the users if filename cannot be opened.
$self->WriteContentToFile($mech, "weekly_specials.hmlt");