WWW::Mechanize::Chrome : random complaining that Log4perl is not initialised and test fails
1 direct reply — Read more / Contribute
|
by bliako
on Aug 11, 2025 at 16:54
|
|
|
Log4perl: Seems like no initialization happened. Forgot to call init()
+?
23:28:21 Sent 'Target.closeTarget' message $VAR1 = '{"id":11,"params":
+{"targetId":"F75959D2137237798CF1FCB89E87FFAA"},"method":"Target.clos
+eTarget"}';
23:28:21 Can't call method "irand" on an undefined value at (eval 140)
+ line 17 during global destruction.
As an example, consider the following test-script. For me, the below script sometimes passes and sometimes it fails (see below for when exactly), although all subtests succeed all the time.
#!/usr/bin/env perl
use Test::More;
use WWW::Mechanize::Chrome;
use Log::Log4perl qw(:easy);
# This is for the mech obj, Set priority of root logger to ERROR
Log::Log4perl->easy_init($ERROR);
my %default_mech_params = (
headless => 1,
# log => $mylogger,
launch_arg => [
'--window-size=600x800',
'--password-store=basic', # do not ask me for stupid chrome ac
+count password
# '--remote-debugging-port=9223',
# '--enable-logging', # see also log above
'--disable-gpu',
'--no-sandbox',
'--ignore-certificate-errors',
'--disable-background-networking',
'--disable-client-side-phishing-detection',
'--disable-component-update',
'--disable-hang-monitor',
'--disable-save-password-bubble',
'--disable-default-apps',
'--disable-infobars',
'--disable-popup-blocking',
],
);
my $mech_obj = WWW::Mechanize::Chrome->new(%default_mech_params);
ok(defined($mech_obj), "WWW::Mechanize::Chrome->new() : called.") or B
+AIL_OUT("failed to create WWW::Mechanize::Chrome object");
done_testing();
Here is what it says when I run make all && make test. Note that this fails all the time.
Manifying 1 pod document
PERL_DL_NONLAZY=1 "/usr/bin/perl" "-MExtUtils::Command::MM" "-MTest::H
+arness" "-e" "undef *Test::Harness::Switches; test_harness(0, 'blib/l
+ib', 'blib/arch')" t/*.t
t/xx.t .. 1/? Log4perl: Seems like no initialization happened. Forgot
+to call init()?
2025/08/11 23:40:43 Sent 'Target.closeTarget' message $VAR1 = '{"metho
+d":"Target.closeTarget","id":11,"params":{"targetId":"FF3672A330F5788
+556F1B4B18CCC5610"}}';
2025/08/11 23:40:43 Can't call method "irand" on an undefined value at
+ (eval 140) line 17 during global destruction.
t/xx.t .. Dubious, test returned 255 (wstat 65280, 0xff00)
All 1 subtests passed
Test Summary Report
-------------------
t/xx.t (Wstat: 65280 (exited 255) Tests: 1 Failed: 0)
Non-zero exit status: 255
Files=1, Tests=1, 11 wallclock secs ( 0.03 usr 0.00 sys + 0.41 cusr
+ 0.12 csys = 0.56 CPU)
Result: FAIL
Failed 1/1 test programs. 0/1 subtests failed.
make: *** [Makefile:873: test_dynamic] Error 255
However, when I run make all && perl -Iblib/lib t/xx.t, sometimes it fails with above complaining and sometimes it succeeds.
I use the latest W:M:C v0.73. It fails with perl v5.40.2. On another computer with perl v5.38.2 I see no failures (after 10 consecutive runs). Both running latest linux.
Thanks, bw, bliako
ps. my question is not urgent, don't stop swimming to answer it...
ps2. OT but Corion does the dreadful Log4* abomination Log::Log4perl need to be used by WWW::Mechanize::Chrome?
|
Using system sort order
3 direct replies — Read more / Contribute
|
by sciurius
on Aug 11, 2025 at 05:59
|
|
|
Dear monks,
I want my perl program to sort just like the system it is running on.
This is trivial on Linux, but somehow seems complicated on Windows and macOS.
I use the following test program
#! perl
use strict;
use warnings;
use utf8;
binmode STDOUT => ':utf8';
my @words = ( "Maria Lenore", "Mária Helena", "María Dolores" );
my @sorted = sort @words;
if ( "@sorted" eq "María Dolores Mária Helena Maria Lenore" ) {
print("Sorted OK\n");
}
elsif ( "@sorted" eq "Maria Lenore María Dolores Mária Helena" ) {
print("Sorted C (ASCII)\n");
}
else {
print("Sort failed: @sorted\n");
}
On Windows, I get
PS C:\Users\Johan> perl locale.pl
Sorted C (ASCII)
PS C:\Users\Johan> perl -Mlocale locale.pl
Sorted C (ASCII)
PS C:\Users\Johan>
Same on macOS.
When I create files with names "Maria Lenore", "Mária Helena" and "María Dolores" they sort correctly in the Explorer (Windows) and Finder (macOS).
How can I have perl use the same sort order as the system?
Windows 10 with Strawberry Perl 5.30
MacOS 10.15 with Perl 5.34.
These versions are a bit old, but I can not imagine I'm the first to try such a sort in 25+ years.
|
How to pass custom options to pod2man from Extutils::MakeMaker?
1 direct reply — Read more / Contribute
|
by nicholashubbard
on Aug 10, 2025 at 14:00
|
|
|
With ExtUtils::MakeMaker, I would like to set the title of my manpage using pod2man's "--center" option. Unfortunately I cannot figure out how to do this. I have read through Makemakers doumentation but cannot find any mention of passing custom flags to pod2man. I noticed that in MakeMaker's outputted Makefile, there is a rule "manifypods" that handles creating the manpages with pod2man. However, I cannot figure out how to customize this rule. I noticed that pod2man is executed via a function "ExtUtils::Command::mm::pod2man, that does allow passing options, but I'm unsure of how I can gain control of this functions invocation.
Does anybody know how I can do this? Does anybody know of any other projects that pass custom options to pod2man from ExtUtils::MakeMaker?
|
unpack Binary FAIL
2 direct replies — Read more / Contribute
|
by marinersk
on Aug 07, 2025 at 20:09
|
|
|
I'm sure this is going to be really basic, but I've gone several decades using Perl and never needed the pack or unpack functions before.
#!/usr/bin/perl
use strict;
use warnings;
#
my $pReqsca = "ABCD";
my @bytary = unpack 'C*', $pReqsca;
+
my $binstr = '';
+
foreach my $scabyt (@bytary) {
+
my $intbyt = int($scabyt);
+
my $hexbyt = sprintf("%02X", $intbyt);
+
my $binbyt = unpack 'b8', $scabyt;
+
$binstr .= $binbyt;
+
print " Byte = [$scabyt] Integer = [$intbyt] Hex = [$hexbyt] B
+inary = [$binbyt] Binary String = [$binstr]\n";
print "Aborting Loop\n";
last;
}
Results:
W:\Steve\PerlMonks>perl sopw-584100.pl
Byte = [65] Integer = [65] Hex = [41] Binary = [01101100] Binary
+ String = [01101100]
Aborting Loop
Same results using 'B8',
Last time I checked, Hex 41 should show binary 01000001.
What am I missing here?
|
Module to deal with PGP-encrypted email messages in 2025
1 direct reply — Read more / Contribute
|
by Nocturnus
on Aug 07, 2025 at 13:16
|
|
|
Dear well-respected monks,
I was wandering in the darkest night without any hope and orientation, but finally saw the promising lights of the monastery. The heart began to beat again, and I dare to ask you for your wisdom regarding the following question:
I need to deal with PGP-encrypted email messages. To be precise, I would like to permanently decrypt thousands of PGP-encrypted email messages that I have on disk in the form of .eml files.
To my surprise, I haven't found a PGP module for Perl that actually is usable in 2025 with recent Perl versions. Mail::PGP Mail::GPG seemed like a good candidate, but I now have lost nearly two days with trying to install it using CPAN in three different environments (Cygwin, Strawberry Perl / Native Windows and Linux). It seems that it cannot be used with recent Perl versions any more; no wonder that I've failed in trying to make it work.
Then there is Mail:GnuPG. It seems to be the predecessor of Mail:PGP, seems to contain some bugs, and seems to be even more outdated. I managed to install it under Linux, but failed to install it under Cygwin and under Strawberry Perl. The latter would not be the key point, but for certain reasons it would simply be more comfortable for me to run the script under native Windows. At least, Mail::GnuPG could be the last resort.
I am quite sure that I have missed something. What module would you, dear monks, use nowadays to decrypt PGP-encrypted email messages?
To avoid misunderstandings:
This question is about email messages that mostly contain nested MIME structures. When decrypting, all mail headers, MIME parts and attachments of the respective message should be preserved or decrypted, respectively. This means that I cannot use the Perl modules that can handle PGP on ordinary files; that would indeed be a no-brainer.
Furthermore, I could use the GnuPG application directly to permanently decrypt those messages; I have verified that this is possible in general. However, when doing this, the mail headers of the original message do not exist any more in the decrypted version. Instead, the decrypted version contains the headers that were in the encrypted part of the original message. For example, the Date header gets lost; funnily enough, it exists only as a non-encrypted header in the original message.
When anything else fails, I'll eventually take that route: Decrypt using the GnuPG application directly, then merge the headers from the original message with those of the decrypted message. As mentioned above, I'd like to listen to the monks before I take that effort.
Your devoted novice Nocturnus
|
Bluetooth LE?
1 direct reply — Read more / Contribute
|
by cavac
on Aug 05, 2025 at 04:37
|
|
|
I'm trying to connect to a Bluetooth LE (low energy) device, specifically the MXTP-100 printer (that extremely cheap thermal printer with the cat ears). I tried Net::Bluetooth, but that doesn't seem to support Low Energy devices.
I can connect and print just fine to an old Epson bluetooth printer (not LE), but newer LE devices don't seem to work with Net::Bluetooth.
To be honest, i have absolutely no idea what i'm doing. Does anyone have any suggestions?
EDIT: Ooops, sorry, forgot to include my test code:
(I just hacked one of the examples, so code quality is low. Also please ignore the mentioning of GPS, i just didn't bother to update all variable names and comments)
|
Possessive sub-pattern with non-greedy content + recursion: WHY does this work??
3 direct replies — Read more / Contribute
|
by Anonymous Monk
on Aug 04, 2025 at 11:42
|
|
|
Say, a string has embedded palindromes (PD); a PD in this case has odd (at least 3) number of letters. I want a piece of code to be executed exactly once for every PD including nested ones. Let "piece of code" be 'say'. Regex to extract a PD is well-known, and of course TIMTOWTDI, the question is not how to better solve the task.
Almost accidentally I found a solution, which I'm puzzled about. I don't know if it could be a simpler SSCCE without recursion.
say 'match' if 'abABCDCBAdeXYZYXfg' =~ /
(?>^.*?)
(
(
(.)(?-3)\g-1 | (.).\g-1
)
(?{
say $2
})
)
/x;
Output:
YZY
XYZYX
CDC
BCDCB
ABCDCBA
Bingo, just what I need. Match fails -- it's irrelevant. But HOW? If either of the following is removed: (1) "^" anchor; (2) independence (s/>/:/), or (3) entire 1st pair of parens, then there are multiple visits to each PD i.e. not what I want. In fact, for (3) the PD groups are also visited in reversed order, this I don't understand neither. And why both PD groups (not only 1st one) are visited.
Being greedy (s/\*\?/*/) produces no output, this I understand (I hope).
If, in case of code above i.e. without removing anything, the engine gives characters back one by one (I thought this is how backtracking works) before it ultimately fails when it (suddenly, somehow) remembers about independence, then I'd expect YZY is found and said; and then XYZYX is found and embedded code executed for both YZY and XYZYX, i.e. both are said (i.e. YZY said twice in total).
P.S. I've seen "Embedded Code Execution Frequency" section in perlre.
|
Documentation for ->&
2 direct replies — Read more / Contribute
|
by ikegami
on Aug 03, 2025 at 13:40
|
|
|
|
|
Running multi task
1 direct reply — Read more / Contribute
|
by joyfedl
on Aug 02, 2025 at 14:46
|
|
|
I have a sample data, my question is that what is the best way to run multi-task, the URL API Endpoint is the one which is different but the tasks are the same like
my $url = "https://v3.football.api-sports.io/fixtures?live=1";
my $url = "https://v3.football.api-sports.io/fixtures?live=2";
my $url = "https://v3.football.api-sports.io/fixtures?live=3";
i was thinking on that this could work after code block i put continue Loop then other code block
my problem is that i don't want to make multiple files which does same work, i want to include them in same file and run once
#!/usr/bin/perl -wT
use strict;
use warnings;
use LWP::UserAgent;
use HTTP::Request;
use JSON;
use DBI;
my $host = "";
my $usr = "";
my $pwd = "";
my $dbname = "";
my $dbh = DBI->connect("DBI:mysql:$dbname:$host", $usr, $pwd, {
AutoCommit => 1,
RaiseError => 1,
}) or die $DBI::errstr;
my $url = "https://v3.football.api-sports.io/fixtures?live=1";
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => $url);
$req->header('x-rapidapi-host' => 'v3.football.api-sports.io');
$req->header('x-rapidapi-key' => 'e73299760f882d');
my $response = $ua->request($req);
my $parse_json = JSON::XS->new->decode ($response->content);
if ($response->is_success) {
for my $match (@{$parse_json->{response}}) {
my $elapsed = $match->{fixture}{status}{elapsed};
my $status = $match->{fixture}{status}{short};
my $home = $match->{teams}{home}{name};
my $away = $match->{teams}{away}{name};
my $ht_home = $match->{score}{halftime}{home} // 'N/A';
my $ht_away = $match->{score}{halftime}{away} // 'N/A';
my $ft_home = $match->{score}{fulltime}{home} // 'N/A';
my $ft_away = $match->{score}{fulltime}{away} // 'N/A';
my $query = $dbh->prepare("# MYSQL QUERY");
$query->execute();
my $query_data = $query->fetchrow_array;
$query->finish;
# more select below.............
if (int($elapsed > 0)) {
my $Create = $dbh->prepare("# MYSQL QUERY)
VALUES()");
$Create->execute();
$Create->finish();
}
# more insert below.............
}
} else {
print $response->status_line;
}
$dbh->commit;
$dbh->disconnect;
|
New release of Text::CSV_XS won't build on Windows, prob a gcc input error (CygwinPerl)
3 direct replies — Read more / Contribute
|
by Intrepid
on Aug 01, 2025 at 17:41
|
|
|
I'm at it again: reveling in debugging the build of Someone Else's Code ;-). In this
case, Someone is H. Merijn Brand with his recent release of
Text::CSV_XS on CPAN.
EDIT
I don't want to give a false impression of my motivations, and where I wrote
above that I "revel in debugging ..." I could be misunderstood. I don't take
pleasure in calling anyone out for lack of skill, lack of knowledge, or
carelessness. Rather, I revel in having a problem I can apply my own efforts to
solving while seeing contributions from my fellow nuns and monks who spot things
that I have missed. The collaboration is what I revel in. Thanks, now back to the matter
at hand.
Looking closely at the compiler-related messages below, two things stand out as strange
(see below in the "On Cygwin Perl..."):
-ffile-prefix-map=/mnt/share/cygpkgs/perl/perl.x86_64/build=/usr/src/debug/perl-5.40.2-1
-and-
-ffile-prefix-map=/mnt/share/cygpkgs/perl/perl.x86_64/src/perl-5.40.2=/usr/src/debug/perl-5.40.2-1
I don't have those paths, and self-evidently anything that starts with /mnt/ is
not going to be portable, anyhow.
What happens on Gnu/Linux:
cp CSV_XS.pm blib/lib/Text/CSV_XS.pm
Running Mkbootstrap for CSV_XS ()
chmod 644 "CSV_XS.bs"
"/usr/local/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- CSV_
+XS.bs blib/arch/auto/Text/CSV_XS/CSV_XS.bs 644
"/usr/local/bin/perl" "/usr/local/lib/perl5/site_perl/ExtUtils/xsubpp"
+ -typemap '/usr/local/lib/perl5/5.40.1/ExtUtils/typemap' CSV_XS.xs
+> CSV_XS.xsc
mv CSV_XS.xsc CSV_XS.c
cc -c -D_REENTRANT -D_GNU_SOURCE -fwrapv -fno-strict-aliasing -pipe
+-fsORTIFY_SOURCE=2 -O2 -DVERSION=\"1.61\" -DXS_VERSION=\"1.61\" -fP
+IC "-I/usr/local/lib/perl5/5.40.1/i686-linux-gnu-thread-multi/CORE"
+ CSV_XS.c
rm -f blib/arch/auto/Text/CSV_XS/CSV_XS.so
cc -shared -O2 -L/usr/local/lib -fstack-protector-strong CSV_XS.o -
+o blib/arch/auto/Text/CSV_XS/CSV_XS.so \
\
chmod 755 blib/arch/auto/Text/CSV_XS/CSV_XS.so
Manifying 1 pod document
On Cygwin Perl 5.40.2 with gcc 13.4.0 what happens:
[MSG] [Thu Jul 31 18:03:07 2025] Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for Text::CSV_XS
Writing MYMETA.yml and MYMETA.json
[MSG] [Thu Jul 31 18:03:07 2025] DEFAULT 'filter_prereqs' HANDLER RETU
+RNING 'sub return value'
[ERROR] [Thu Jul 31 18:03:23 2025] MAKE failed: No such file or direct
+ory cp CSV_XS.pm blib/lib/Text/CSV_XS.pm
Running Mkbootstrap for CSV_XS ()
chmod 644 "CSV_XS.bs"
"/usr/bin/perl.exe" -MExtUtils::Command::MM -e 'cp_nonempty' -- CSV_XS
+.bs blib/arch/auto/Text/CSV_XS/CSV_XS.bs 644
"/usr/bin/perl.exe" "/usr/local/share/perl5/site_perl/5.40/ExtUtils/xs
+ubpp" -typemap '/usr/share/perl5/5.40/ExtUtils/typemap' CSV_XS.xs >
+ CSV_XS.xsc
mv CSV_XS.xsc CSV_XS.c
gcc -c -U__STRICT_ANSI__ -D_GNU_SOURCE -ggdb -O2 -pipe -Wall -Werror
+=format-security -D_FORTIFY_SOURCE=3 -fstack-protector-strong --param
+=ssp-buffer-size=4 -ffile-prefix-map=/mnt/share/cygpkgs/perl/perl.x86
+_64/build=/usr/src/debug/perl-5.40.2-1 -ffile-prefix-map=/mnt/share/c
+ygpkgs/perl/perl.x86_64/src/perl-5.40.2=/usr/src/debug/perl-5.40.2-1
+-fwrapv -fno-strict-aliasing -DUSEIMPORTLIB -O3 -DVERSION=\"1.61\"
+-DXS_VERSION=\"1.61\" "-I/usr/lib/perl5/5.40/x86_64-cygwin-threads/C
+ORE" CSV_XS.c
rm -f blib/arch/auto/Text/CSV_XS/CSV_XS.dll
g++ --shared -Wl,--enable-auto-import -Wl,--export-all-symbols -Wl,-
+-enable-auto-image-base -fstack-protector-strong CSV_XS.o -o blib/a
+rch/auto/Text/CSV_XS/CSV_XS.dll \
/usr/lib/perl5/5.40/x86_64-cygwin-threads/CORE/cygperl5_40.dll -lpth
+read -ldl -lcrypt \
make: *** [Makefile:484: blib/arch/auto/Text/CSV_XS/CSV_XS.dll] Aborte
+d
make: *** Deleting file 'blib/arch/auto/Text/CSV_XS/CSV_XS.dll'
[ERROR] [Thu Jul 31 18:03:23 2025] Unable to create a new distribution
+ object for 'Text::CSV_XS' -- cannot continue
If anyone running CygPerl on Windows gets a different result trying to build
Text::CSV_XS, please let me know in the thread, thanks.
- Soren
Aug 01, 2025 at 21:39 UTC
A just machine to make big decisions
Programmed by fellows (and gals) with compassion and vision
We'll be clean when their work is done
We'll be eternally free yes, and eternally young
Donald Fagen —> I.G.Y.
(Slightly modified for inclusiveness)
|
|