notes

There are notes or example code pieces for historical purposes

data url

#!c:\usr\bin\perl.exe -w use MIME::Base64; use open IN => ':raw', OUT => ':raw'; binmode STDOUT; our %mime = ( 'gif' => 'image/gif', 'svg' => 'image/svg+xml', 'png' => 'image/png', 'ico' => 'image/x-icon', 'txt' => 'text/plain', 'htm' => 'text/html', 'html' => 'text/html', ); foreach $file (@ARGV) { local $/; $file =~ m{\.([^\.]*)$}; my $ext = $1 || ''; open(my $fh, '<', $file) or die $!; binmode $fh; print "data:" . ($mime{$ext}||'application/octet-stream') . ";base64," . encode_base64(<$fh>, ''); close($fh); }

base64

enocde64.pl

#!c:\usr\bin\perl.exe -w use MIME::Base64; use open IN => ':raw', OUT => ':raw'; binmode STDOUT; local $/; print encode_base64(<>);

decde64.pl

#!c:\usr\bin\perl.exe -w use MIME::Base64; use open IN => ':raw', OUT => ':raw'; binmode STDOUT; local $/; print decode_base64(<>);

findPerlMod

#!perl -l die "usage:\n\t$0 Perl::Module::One [Optional::Perl::Modules...]" unless @ARGV; foreach (@ARGV) { my $k = $_; $k =~ s{::}{/}g; $k =~ s{(?<!\.pm)$}{.pm}i; # this will add .pm to the end, unless it's already there... [perldoc perlre # zero-width engative lookbehind] eval{require $k} unless exists $INC{$k}; unless(exists $INC{$k}) { print "$_ => {could not find $k}"; next; } (my $v = $INC{$k}) =~ s{/}{\\}g; print "$_ => $v"; }

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 } <DATA>; # 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!

win32::gui notes

- Overhead and border: x:(16,10), y:(39,10) - Fonts: create new font through my $f=Win32::GUI::Font::->new(), and attach it as attribute of its parent window $win->{_attach_font} = $f; (so it doesn't go out of context as it is running) - ENTRY boxes are Textfield() objects - Combobox and Textfield should be 21 high with default fonts, and Label needs vertical offset of 4px to align text in the Label with text in the Textfield or Combobox - Combobox (https://learn.microsoft.com/en-us/windows/win32/controls/about-combo-boxes) -simple ⇒ Always shown down ("Displays the list at all times, and shows the selected item in an edit control.") -dropdown ⇒ drop down, and editable ("Displays the list when the icon is clicked, and shows the selected item in an edit control.") -dropdownlist ⇒ drop down, but not editable ("Displays the list when the icon is clicked, and shows the selected item in a static control.") - Win32::GUI::Grid and Win32::GUI::AxWindow can only be compiled if using MSVC to compile, instead of Strawberry's mingw gcc, so don't get those with Strawberry installations.

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]
  • [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:
  • Handling Windows 'Junctions'
  • 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:
  • [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:

  • 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


    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


    Videos


    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

    page look-and-feel inspired by lifehacker.me