notes
There are notes or example code pieces for historical purposes
used modules?
This script allows me to find the perl modules that I'm actually using in some set of directories
#!perl
use 5.012; # strict, //
use warnings;
use Path::Tiny;
my @modules = map { s/^.*?"Module" //r =~ s/[\r\n]+$//r } ;
# print for @modules;
my @search_folders = map { path($_) } qw(
c:/usr/local/scripts
c:/usr/local/share
c:/usr/local/share/sandbox
c:\users\peter.jones\downloads\tempdata
);
my %used;
for my $p ( @search_folders ) {
my $iter = path($p)->iterator({recurse=>1, follow_symlinks=>0});
while( my $entry = $iter->() ) {
next if $entry =~ m(\.svn/);
next unless $entry =~ m(\.p[lm]$)i;
#print "$entry\n";
for(grep { m(^\h*use) } map { split /;/, $_ } grep { m(^\h*use) } $entry->lines({chomp=>1})) {
s/#.*$//;
s/^\h*//g;
s/\h*$//g;
m/use\h*('.*?'|".*"|.+?)(?:\h+(.*)$)?$/ and do {
push @{ $used{$1} }, "$entry";
};
}
}
}
use Data::Dump; #dd \%used;
for my $module ( @modules ) {
local $\ = $/;
#dd $module, $used{$module}//'' if exists $used{$module};
print $module if exists $used{$module};
}
# grab the results of `perldoc perllocal`,
# then strip out all the ones to perl\lib and perl\vendor\lib (which were installed by strawberry)
# leaving only ones with perl\site\lib
# Paste the results in the _DATA_ section:
__DATA__
Tue Nov 2 19:05:39 2021: "Module" WWW::KeePassRest
...
win32log
To get logging to "common areas" in Win32:
- Event Viewer
- Sys::Syslog:
- $ident: This is the "source" column of Event Viewer
- $logopt: string of comma-separated tokens
- ndelay: no delay before connecting
- pid: seems to be irrelevant to Win32
- perror: seems to be irrelevant to Win32
- example: ndelay,perror
- $facility: use :macros LOG_xxx constants or string
- LOG_USER / "user": generic (Event ID = 157)
- LOG_SYSLOG / "syslog": syslogd (Event ID = 133)
- LOG_LOCALn / "localn": local, with n ∈ [0..7] (Event ID = 140..147)
- $priority: use :macros LOG_xxx constants or string
- LOG_DEBUG / LOG_INFO: 🛈 Information
- LOG_NOTICE / LOG_WARNING / LOG_EMERG: ⚠ Warning (LOG_EMERG should really be below)
- LOG_ERR / LOG_CRIT / LOG_ALERT: ⚠ Error
- Log::Any::Adapter::Syslog: uses Sys::Syslog in a Log::Any environment
- Event Viewer:
- Go to the Windows Logs > Application tab
- Filter Current Log: Last Hour (custom sources don't appear to be in Event Sources filter)
- OutputDebugString() → Sysinternals DebugView
- Win32::OutputDebugString($string)
- DbgView64.exe
- Include: use some common string (prefix, etc) in the OutputDebugString() call, and filter on that
- Exclude: matches to ignore
- Highlight: there are 20 different search terms, with each getting its search expression in the colored dropdown
debug in notepad++
the conversation here
made me think about Perl+DBGp in Notepad++ again, since there's a x64 build of the plugin now. I tried to get it to work based on Michael Vincent's
old x86 instructions in his blog, but trying with the
perl5db.pl that ships with Strawberry Perl, but it wouldn't actually pause. However, grabbing a 32-bit NPP and following his
pm version of the instructions exactly, I was able to get it to work.
So I then took that modified perl5db.pl and DB subdirectory into the x64 NPP, and took the hint from
@rdipardo's repo for the x64 plugin which said that the port changed from 9000 to 9003,
and with those changes, a hello-world script would actually pause:
set PERL5LIB=C:\Program Files\Notepad++\plugins\PerlDebug
set PERLDB_OPTS=RemotePort=127.0.0.1:9003
REM Plugins|DBGp|Debugger|TurnON
perl -d tryNppDebugger.pl
The perl correctly launches but doesn't return to command line, and I'm able to single-step through and see variables.
However, I don't like that I have to "borrow" from Komodo source code to get that DB directory. Some searching found
Devel::Debug::DBGp. Looking through their source, they might
still have the CDATA fix in DB\DBgrProperties.pm, but don't appear to have the context_id/context; and the
perl5db.pl fixes seem to already be there. Unfortunately, trying to install that module and its dependencies
fails for me -- cpantesters shows no
installations in win32, so blech. (The DBGp::Client test suite failed, and when I --notest on that one, the
Devel::Debug::DBGp won't compile its XS correctly. The DBGp::Client has never passed on >perl5.24, and that only on 0.06
compared to 0.12 recent release -- thus, I don't think getting it to install is likely.) I might be able
to just extract the non-XS bits.
Tried with the non-XS bits: modified the DB\DBgrProperties.pm, and found that it mostly worked, but
has the "local context" that Michael had mentioned, which the context_id/context change had fixed.
There we go: DB\DbgrContext.pm has a context_id="%d" -- change it to context="%d" and
now the context works correctly, and it can debug. Hurrah!
perlmonks scratchpad
migrated my perlmonks scratchpad, because there are times I want to look up some of these notes when pm has been down
Links for quick reference
2021-Feb-11: saw [erzuuli] [abbr://CB]
[abbr://PM], so now I must test: try
[abbr://PM] = [abbr://PM] or
[abbr://Auto Abbrev|After Pipe] = [abbr://Auto Abbrev|After Pipe] or
[abbr://SSCCE] = [abbr://SSCCE]
include the codified version for easy copy/paste
[id://1177642] = [id://1177642]
%:: hash contains all the top-level, and %::Win32:: contains all the entries in the Win32 namespace. oh, right, documented in [doc://perlmod#Symbol-Tables]
Floating Point
[https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html| What Every Computer Scientist Should Know About Floating-Point Arithmetic] = [https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html| What Every Computer Scientist Should Know About Floating-Point Arithmetic]
[metamod://Data::IEEE754::Tools] = [metamod://Data::IEEE754::Tools]
[href://?node_id=3989;BIT=floating;a=pryrt] = [href://?node_id=3989;BIT=floating;a=pryrt]
- First mention of [METAMOD://Data::IEEE754::Tools] @ [id://1165802]
- Digits of decimal expansion of binary float @ [id://1168363]
[metamod://Devel::Peek]::Dump() for showing NV, IV, ...
Monastery HowTo
[id://590089] = Free Nodelet help
[id://1153804] = Free Nodelet code to allow WikiSyntax for posting in the Monastery
Long-Term Bookmarks
Book: [http://hop.perl.plover.com/book/|Higher Order Perl]
[id://1175234|Perl REPL suggestions] -- BUK's includes windows memory usage sub mem { `tasklist /nh /fi "PID eq $$"`=~ m[(\S+ K)$] }
[id://1153468|bug in eval]: eval { die }; if($@) {...} might not work; use eval { die; 1 } or do {...} or [mod://Try::Tiny] instead
Perl Debugging aids:
- [metamod://Devel::Peek]::Dump() for showing NV, IV, ...
- perl -c to compile without running
- [id://11103823] shows perl -MO=Deparse ... for rephrasing and -MO=Concise for the opcode tree
Handling Windows 'Junctions'- [id://1178059|[id://1178059]] (2016-Dec)
- [id://1223819|[id://1223819]] (2018-Oct)
- private repo: [https://subversion.assembla.com/svn/pryrt/trunk/perl/perlmonks/junctions.pl] (2018-Oct)
KeePass
▶ [http://www.vivtek.com/perl/keepassrest.html|KeePassRest]: access KeePass via REST-ful API (from thread [id://1061396]) => please note that KeePassRest requires a license to a separate product
▶ [id://1183260|Excellent discussion of passwords in scripts] / [id://1185953|w/ keepass]
▶ [id://11138920]: my foray into Perl/KeePass integration
CGI: [metamod://FCGI] + [metamod://CGI::Fast] | [id://1185731|alt] [id://1180993|hippo++] | [metamod://CGI::Lite|CGI::Lite (core)] [metamod://CGI::Simple] [metamod://CGI::Minimal] [metamod://CGI::Thin] | [metamod://Mojolicious::Lite] [metamod://Mojolicious::Guides::Tutorial|Tutorial] and [metamod://Mojolicious::Guides::Cookbook|Cookbook] | [http://blag.nullteilerfrei.de/2013/05/17/building-perl-stand-alone-applications-with-a-gui-using-mojolicious-and-par-packer/|Mojo+ParPacker] | [id://1193932|includes link to some mojo docs I haven't looked at]
| [id://11118101|Mojo::Lite First Steps] |
[id://830550] -- has multiple Mojo/Mojo::Lite examples
Websockets:
- per [https://community.notepad-plus-plus.org/topic/24673/plugin-request-ghosttext-support|N++ GhostText request], I finally have something that might encourage me to try to write a Mojo-based server that handles websockets, and maybe start to understand what they're all about
- [https://blogs.perl.org/users/joel_berger/2012/10/a-websocket-mojoliciousdbi-example.html|Mojo Websocket Example w/ DBI] by jberger
- [id://1130920] -- reply links to jberger's github repo [http://jberger.github.io/MojoliciousIntroduction/#/|MojoliciousIntroduction], and provides some steps toward getting a working server (websocket '/echo') and client (the js embedded in the get '/' and index.html.ep)
[id://1193868] → [id://579282] → for win32 unicode access of files, use open(my $fh, '<...', $fn) or open(my $fh, '>...', $fn), where '...' is :raw:utf8, :raw:encoding(utf16le), or :raw:encoding(utf16be) (as appropriate): modern note: [doc://open] shows :encoding(UTF-8) as well; [doc://PerlIO] indicates that :utf8 doesn't validate sequences on input, so :encoding(UTF-8) should be used instead ([doc://PerlIO::encoding])
[id://1004474] => CPAN Testers: PASS/FAIL vs UNKNOWN vs NA (and how to return each to CPAN Tester Matrix)
[id://11140872] => wrapping Shell commands in oo notation: I had seen [mod://IPC::Run3::Shell] from [haukex], but not [mod://IPC::Run3::Shell::Wrapper], which does the next step, and could be used for my wrapping of openssl and similar, I think.
[mod://Log::Any] goes in .pm, [mod://Log::Any::Adapter] goes in the calling .pl application; if you want to redirect application STDERR to the Adapter, then use [mod://Log::Any::For::Std] in the .pl application as well
Permutations/Combinations:
- [mod://Algorithm::Permute] - either iterator or callback; just permute
- [mod://Algorithm::Combinatorics] - iterator; permutations, combinations, derangements, variations, subsets, ...
- [mod://Math::Combinatorics] - iterator or dump; permute, combine, factorial
Windows and PAR::Packer
Inspired by [http://blag.nullteilerfrei.de/2013/05/17/building-perl-stand-alone-applications-with-a-gui-using-mojolicious-and-par-packer/|this blog] (which was linked from [dasgar]'s [id://1187819|post]):
C:\TEMP> mkdir tmp
C:\TEMP> echo blah >> tmp\a.txt
C:\TEMP> echo blah blah >> tmp\a.txt
C:\TEMP> echo blah blah blah >> tmp\a.txt
C:\TEMP> pp -o hello.exe -a tmp -e "use File::Spec; BEGIN { if(exists $ENV{PAR_TEMP}) { my $d = File::Spec->catfile($ENV{PAR_TEMP}, 'inc'); chdir
$d or die qq(chdir '$d' failed: $!); }; }; open my $fh, '<', 'tmp/a.txt' or die qq(tmp/a.txt: $!); foreach (<$fh>) { print qq(a: $_); }"
C:\TEMP> cd ..
C:\> TEMP\hello.exe
a: blah
a: blah blah
a: blah blah blah
That's pretty cool. While testing that out, I was using both my "system" strawberry perl and my berrybrew perls, and discovered that I need to cpanm --force PAR::Packer, because of a compiler warning/error during one of the testing steps (of sha1.c). It installs and seems to work, but given the message
gcc -c -s -O2 -DWIN32 -DWIN64 -DCONSERVATIVE -DPERL_TEXTMODE_SCRIPTS -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS -fwrapv -fno-strict-aliasing -mms-bitfields -I"C:\usr\local\apps\strawberry\perl\lib\CORE" -DPARL_EXE=\"parl.exe\" -DPAR_PACKER_VERSION=\"1.036\" -s -O2 boot.c
In file included from mktmpdir.h:85:0,
from mktmpdir.c:1,
from boot.c:10:
sha1.c: In function 'sha_transform':
sha1.c:146:2: warning: right shift count >= width of type
T >>= 32;
^
... I am not sure that it will properly hash. (the 32bit perl installations didn't have that error, and so didn't need --force)
PAR::Packer quirks
- exe icon: [aplonis]:[id://1193631] ← [pryrt]:[id://1192723] ← [swl]:[id://1171032] ← [http://www.zewaren.net/site/?q=node/116]
I was able to get a local-lib style par-packer that I could use
cpanm --installdeps pp &rem need to make sure all prereqs are in the non-locallib before starting the locallib installation
start cpanm -L .\locallib --look pp &rem will put the `--look` shell in locallib mode
copy some_other_icon.ico myldr\winres\pp.ico &rem update the icon; won't necessarily show updated icon in Explorer.exe unless you run SHChangeNotify†
cpanm --notest . &rem from same shell, so inherits the locallib from `--look`
exit &rem leaves the `--look` shell
then, if I do a batch wrapper which runs
setlocal
PATH=c:\path\to\locallib\bin;%PATH% &rem PATH=%~do0locallib\bin;%PATH% &rem ... the second works in a .bat/.cmd
set PERL5LIB=C:\path\to\locallib\lib\perl5 &rem set PERL5LIB=%~dp0locallib\lib\perl5 &rem ... the second works in a .bat/.cmd
pp -x -o out.exe in.pl &rem see longer version, below
... I can call the locallib version of pp with its customized icon, thus ensuring that my out.exe has the customized icon
†: SHChangeNotify(SHCNE_ASSOCCHANGED,SHCNF_IDLIST,NULL,NULL) will normally refresh icons for Explorer.exe
pp --gui -M ... --link=c:.../strawberry/c/bin/libexpat-1__.dll -x -a myIcoin.ico -o out.exe in.pl
^^^^^^^^^^^^^^ = use -a for embedding icons and other resources
^^ = -x means get dependency from `perl in.pl`; -c means from `perl -c in.pl`
^^^^^^^^ = may need to manually link DLLs; can use procexp when the `perl in.pl` is running to see all the libraries
^^^^^^^^^^^^^ = if `in.pl` uses other modules, modules used by those might not always be incorporated, so use one or more -M to ensure they get included
^^^^^ = do not include a console window in win32 executables
- include all XS dlls: [id://1193701] -> pp -x -o out.exe in.pl
- include external DLLs: [id://11151852] -> pp --link c:\path_to_strawberry\c\bin/zlib1__.dll -x -o out.exe in.pl
can use [https://learn.microsoft.com/en-us/sysinternals/downloads/process-explorer|Sysinternals Process Explorer]'s ^D to view the DLLs of a process: any that the .exe is grabbing from the perl hierarchy needs the --link included
Login With ...
After recent discussions of [METAMOD://Mojolicious::Lite] login examples ([id://11118092] and [id://11114542]), and some of my recent thoughts about LDAP, the [id://11118452] question caught my eye: I would love to see one of the example [METAMOD://M::L] apps updated to use Login with Google, Login With Facebook, and similar for other OAuth providers (preferrably multiple providers at once).
This [https://medium.com/@thomashellstrom/use-google-as-login-in-your-web-app-with-oauth3-352f6c7f10e6|medium.com:@thomashelstrom article] shows how he did a quick login-with-Google, which might be a good starting point.
Post [id://11121311] describes possible procedure for using [mod://LWP::Authen::OAuth3] to login with google or similar
Even better, I decided to search Mojo for "OAuth3" and found [mod://Mojolicious::Plugin::OAuth3], which is exactly what I was thinking about without having to re-invent the wheel.
FFI::Platypus
I had seen mention of [METAMOD://FFI::Platypus] before, but [id://11118805] had me take a quick look from a different perspective -- I had thought it was supposed to provide a way to access external libraries, but from the documentation I had linked before, I got too confused. This time, I was able to find [https://metacpan.org/source/PLICEASE/FFI-Platypus-1.31/examples/win32_getSystemTime.pl|an example of accessing kernel32.dll] ... and with that, it _might_ be possible to replace my monster amalgamation of Win32::API, Win32::GUI, and [METAMOD://Win32::GuiTest] -- though I might still want GuiTest separate during the module tests, because it's a pretty clean way for remote-controlling the GUI
Strawberry newer than perl 5.32
- Build My Own Strawberry: [id://11147918] => [id://11128365]
- [id://11149565]
- [id://11150991]
- [id://11150987]
- [https://github.com/StrawberryPerl/Perl-Dist-Strawberry/releases/tag/SP_5380_5361|2023-Jul-10: v5.36.1 and v5.38.0 Released!!!!]
Videos
- [https://www.youtube.com/watch?v=ol_Qk31v17g&t=750s|TPRC 2023 - CI: cpanm logfiles]
- [https://www.youtube.com/watch?v=ENN05EhBkgM|TPRC2022 - Perl Navigator] - alternate [https://github.com/bscan/PerlNavigator|LSP server] for Perl; works with eko's N++ LSP client
Auto-added links
[id://1223175] => shows an example of controlling an interactive program (the bc command) with [METAMOD://IPC::Open3] and [METAMOD://IO::Select]
[id://1204841]: thanks to this article, and the linked [http://perldoc.perl.org/perlvar.html#%24%7B%5EWIN32_SLOPPY_STAT%7D], I think I might be able to use that variable to speed up my at-home backup script...
[id://1213987]
[id://1214548]
[id://11110332] [http://blogs.perl.org/users/sergey_kolychev/2017/02/machine-learning-in-perl.html]
[id://927532]
[id://11146832] describes CHANGES xt\ test to avoid releasing-without-changelog