I am posting invoices to sql-ledger (sql-ledger.org) via WWW::Mechanize:
$request = $self->{_mech}->get('http://localhost/sql-ledger/is.pl?path=bin/mozilla&action=add&level=AR--Sales%20Invoice&login=sync4obmondo@sl-example-aps&js=1&type=invoice');
$self->{_mech}->form_name('main');
$self->{_mech}->field('customernumber','10');
$self->{_mech}->click_button( value => 'Update' ); #submit button 1
$self->{_mech}->form_name('main');
$self->{_mech}->field('transdate', $invoicedate);
$self->{_mech}->field('duedate', $invoicedate);
$self->{_mech}->field('invnumber', $invoice->invoiceNr);
print "entering exch." . $invoice->exchangeRate ."-" if $debug;
#build invoice lines
my $count = 0;
my $invoicelines = ''; my $linedata = '';
my $outputbefore = '';
for my $i (1 .. $invoice->getInvoiceLinesAmount() -1)
{
$count++;
my $line = $invoice->getInvoiceLine($i);
print "line: $count - Entering partnumber".$line->itemPartNr ."
" if $debug;
#BUG TODO: uncomment this to skip 11th line and above - where timeout becomes too great
next if $count >= 11;
$self->{_mech}->field('partnumber_'.$count, $line->itemPartNr);
print "Updating..
" if $debug;
$self->{_mech}->click_button( value => 'Update' ); #submit button 1
if ( $debug ) {
if ( $outputbefore ne '' ) {
my $string = $self->{_mech}->content;
my $diff = diff $outputbefore, $string;
#print $diff;
#print Dumper($diff)
}
$outputbefore = $self->{_mech}->content;
}
#verify return shows description_$count - NOT empty
if ( $self->{_mech}->value('description_'.$count) eq "" ) {
print $self->{_mech}->content;
die("field $count description NOT filled out. was:".$self->{_mech}->value('description_'.$count));
}
$self->{_mech}->form_name('main');
$self->{_mech}->field('qty_'.$count, $line->amount);
$self->{_mech}->field('sellprice_'.$count, $line->price);
$self->{_mech}->field('discount_'.$count, $line->discountPercentage);
print "submitting qty:".$line->amount." sellprice:". $line->price ." discount:".$line->discountPercentage."
" if $debug;
$self->{_mech}->click_button( value => 'Update' ); #submit button 1
}
It hangs on the: $self->{_mech}->click_button( value => 'Update' )
and when an invoice has =>11 lines - my perl process simply goes to a 100% cpu and never finishes (times out after 5 minutes).
Until 9 lines it goes very fast, on the 10. line its slow - and the 11. never finishes before the 600 seconds is up.
I was hoping someone has an idea on what's up here? Or what I can try differently? top shows its my perl process - and not sql-ledger thats slow, and indeed if I manually enter the invoice, I have no issues.
Only hits I can find, is to try www::Mechanize::Firefox - but that's discontinued :(
Would submit_form
perform better than click_button?
I had to paste the html here: https://pastebin.com/Usn36Jb2
it is a humongous form (and not using <form element but some span..)
I'm using WWW::Mechanize version 1.92
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…