Question

I have a program which brings in a page for a book using HTML::TagParser and the book's barcode, grabs a certain span, repeats it for a different page, and then adds it to a TK::MListbox until chosen to export it. This works perfectly fine in Eclipse. However, once made an .exe with par-packer, the program fails to work. The error when using barcode 31412007436751 is this:

Tk::Error: URI::Fetch failed: https://i-share.carli.illinois.edu/uis/cgi-bin/shelflister.cgi?search=s1&bcs=31412007436751&bce=&stpt=1&mode=1 at script/ShelfLister_Lister.pl line 32.
 Carp::croak at C:/strawberry/perl/lib/Carp.pm line 100
 HTML::TagParser::fetch at HTML/TagParser.pm line 261
 HTML::TagParser::new at HTML/TagParser.pm line 239
 main::addBook at script/ShelfLister_Lister.pl line 32
 <Key-Return>
 (command bound to event)

The related program code is this:

#!/user/bin/perl
use strict;
use warnings;
use Tk;
use Tk::MListbox;
use LWP::Simple;
use URI::Fetch;
use Encode::Byte;
use HTTP::Response;
use HTML::TagParser;
use Spreadsheet::WriteExcel;

my ($callNumber, $title, $html, $numItems);
my $savetypes = [['Excel Files', '.xls'], ['Comma-Separated Files', '.csv'], ['Text Files', '.txt']];
my $mw = new MainWindow;
$mw->title("Barcode Lister");
$mw->Label(-text=>'Choose Books')->grid(-row=>1, -column=>1, -columnspan=>2, -pady=>10);
my $barcode = $mw->Entry(-width=>50)->grid(-row=>2, -column=>1, -pady=>5, -padx=>[5, 10]);
my $add = $mw->Button(-text=>'Add Record', -command=>\&addBook, -width=>15)->grid(-row=>2, -column=>2, -pady=>5);
my $listFrame = $mw->Frame(-bd=>2, -relief=>"sunken")->grid(-row=>3, -column=>1, -padx=>[5, 10], -pady=>5);
my $list = $listFrame->Scrolled(qw(MListbox -background white -scrollbars oe))->pack(-expand=>1, -fill=>"both");
$list->columnInsert('end', -text=>"Call number", -width=>23);
$list->columnInsert('end', -text=>"Title", -width=>25);
my $delete = $mw->Button(-text=>'Delete Record', -command=>\&removeBook, -width=>15)->grid(-row=>3, -column=>2, -pady=>5);
my $export = $mw->Button(-text=>'Export List', -command=>\&exportList, -width=>15)->grid(-row=>4, -column=>1, -columnspan=>2, -pady=>5);
$barcode->bind('<Return>'=>\&addBook);
$barcode->focus;

MainLoop;

sub addBook{
    $html = HTML::TagParser->new('https://i-share.carli.illinois.edu/uis/cgi-bin/shelflister.cgi?search=s1&bcs=' . $barcode->get() . '&bce=&stpt=1&mode=1');
    $title = $html->getElementsByClassName('listLine');
    if (ref $title){
        $html = HTML::TagParser->new('https://i-share.carli.illinois.edu/uis/cgi-bin/shelflister.cgi?search=s1&bcs=' . $barcode->get() . '&bce=&stpt=1&mode=2');
        $list->insert("end", [$title->innerText(), $html->getElementsByClassName('listLine')->innerText()]);
        $barcode->delete(0, 'end');
    }
    else{
        $mw->messageBox(-title=>'Error', -message=>"Barcode not found.", -type=>'Ok', -icon=>'error', -default=>'ok');
    }
}

Anyone have any ideas on how I could get this to work as an .exe?

Was it helpful?

Solution

Probably URI::Fetch->errstr would give more information on the failure. Either try to patch HTML::TagParser (see https://rt.cpan.org/Ticket/Display.html?id=86698) or maybe it's possible to wrap your HTML::TagParser-related code lines into an eval { } and call the errstr function yourself on errors.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top