Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

The Monastery Gates

( [id://131]=superdoc: print w/replies, xml ) Need Help??

New here?I want to ask a question of the Perl Monks. Where do I start?

Notices:

hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.

If you're new here, please read PerlMonks FAQ
and Create a new user!

Quests
poll ideas quest 2026
Starts at: Jan 01, 2026 at 00:00
Ends at: Dec 31, 2026 at 23:59
Current Status: Active
0 replies by pollsters
    First, read How do I create a Poll?. Then suggest your poll here. Complete ideas are more likely to be used.

    Note that links may be used in choices but not in the title.

Perl News
Linuxlinks on Perl Static Site Generators
on Feb 20, 2026 at 05:14
0 replies by mldvx4
Perl mentioned at The New Stack
on Feb 13, 2026 at 06:02
3 replies by mldvx4

    The New Stack has mentioned Perl in the context of TIOBE:

    On the scripting side, Perl has also returned to prominence. Once the undisputed leader in scripting, Perl declined after years of internal fragmentation and competition from newer languages, writes Paul Jansen, CEO of TIOBE in the post. “Recently, however, it has staged a comeback, reclaiming a position in the TIOBE top 10 since January 2018,” he writes.

    Perl is actually number 11 on the index right now. It was ranked 30th at the same time last year.

    “It’s hard to judge a programming language’s popularity based on some of the indexes,” Andrew Cornwall, an analyst at Forrester Research, tells The New Stack.

    Statistical language R is making a comeback against Python.

    As we know these rankings are quite arbitrary and the methodology is more than flawed due the selection of repositories surveyed and the ones which get ignored. However, MSFT's long-runnning smear campaign against Perl is losing steam.

Supplications
A little overloading conundrum
2 direct replies — Read more / Contribute
by syphilis
on Mar 06, 2026 at 19:46
    Hi,

    I have a module A that overloads the '-' operator via its A::oload_minus() subroutine.
    And I have a second module B that also overloads the '-' operator via it's own B::oload_minus() subroutine.
    Both modules also have their own oload_add, oload_mul, oload_div, oload_mod and oload_pow subroutines that overload the other basic arithmetic operators).

    I have constructed the overloading in module A to handle B objects.
    But if module B's overloading subroutines are passed a module A object, it is (by my current design) a fatal error.
    use A; use B; $A_obj = A->new(16); $B_obj = B->new(6); my $n1 = $A_obj - $B_obj; # $n1 is an A object with value 10 my $n2 = $B_obj - $A_obj; # Fatal error
    In the above demo I want $n2 to be an A object, with the value of -10.
    That is, I want the A::oload_minus() sub to receive the args ($A_obj, $B_obj, TRUE).
    Instead, the B::oload_minus() sub is receiving the args ($B_obj, $A_obj, FALSE) - which is, by my current design, a fatal error since B::overload_minus() does not currently accept A objects.

    Is there a way that I can work around this without making any changes to the B module ? (The motivation to not alter module B is simply that I don't want to add more clutter to B unless I need to.)

    My module "A" is in fact Math::MPC, and my module "B" is in fact Math::MPFR.

    AFTERTHOUGHT: I should point out that the arithmetic overloading in the publicly available versions of Math::MPC don't yet accept Math::MPFR objects. (I've currently implemented this new feature on my local Math::MPC builds only.)

    Cheers,
    Rob
Type coercion and union
1 direct reply — Read more / Contribute
by tomred
on Mar 06, 2026 at 12:29

    I have the following Type defined.

    package Types; use v5.34; use warnings; use Type::Utils qw( as coerce declare from via ); use Types::Common qw( Enum Str ); use Type::Library -base, -declare => qw( CreditType InvoiceType ); declare InvoiceType, as Enum [qw/ ACCPAY ACCREC /]; coerce InvoiceType, from Str, via { #warn "Trying to coerce $_\n"; my %types = ( Invoice => 'ACCREC', SupplierInvoice => 'ACCPAY', ); #my $ret = $types{$_}; #warn "Returning $ret\n"; return $types{$_}; } ; declare CreditType, as Enum [qw/ ACCPAYCREDIT ACCRECCREDIT /]; coerce CreditType, from Str, via { warn "Trying to coerce $_\n"; my %types = ( Credit => 'ACCRECCREDIT', SupplierCredit => 'ACCPAYCREDIT', ); my $ret = $types{$_}; warn "Returning $ret\n"; return $types{$_}; } ; 1;

    I have a class that uses the types as a union, this or that

    package MyApp; use v5.34; use warnings; use Moo; use Types qw/ InvoiceType CreditType /; has 'type' => ( is => 'ro', isa => InvoiceType | CreditType, required => 1, coerce => 1, ); sub run { my ($self) = @_; say "Running with ".$self->type; } 1;

    I have a test to make sure it's doing what I expect `t/type.t`

    #!/opt/perl5/bin/perl use v5.34; use warnings; use Test::More; use Types qw( InvoiceType CreditType ); { subtest 'Type coercion' => sub { is InvoiceType->coerce('Invoice'), 'ACCREC', 'Can coerce a sales invoice'; is InvoiceType->coerce('SupplierInvoice'), 'ACCPAY', 'Can coerce a supplier invoice'; is CreditType->coerce('Credit'), 'ACCRECCREDIT', 'Can coerce a credit type'; is CreditType->coerce('SupplierCredit'), 'ACCPAYCREDIT', 'Can coerce a supplier credit type'; }; } { my $class = 'MyApp'; use_ok($class); subtest 'Class coercion' => sub { for my $t ( qw/Invoice SupplierInvoice Credit SupplierCredit / + ) { note "Type=$t"; my $x = new_ok($class => [ type => $t ]); note "Now Type=".$x->type; } }; } done_testing;
    t/type.t .. # Subtest: Type coercion ok 1 - Can coerce a sales invoice ok 2 - Can coerce a supplier invoice ok 3 - Can coerce a credit type ok 4 - Can coerce a supplier credit type 1..4 ok 1 - Type coercion ok 2 - use MyApp; # Subtest: Class coercion # Type=Invoice ok 1 - An object of class 'MyApp' isa 'MyApp' # Type=SupplierInvoice ok 2 - An object of class 'MyApp' isa 'MyApp' # Type=Credit not ok 3 - MyApp->new() died # Failed test 'MyApp->new() died' # at t/type.t line 31. # Error was: Undef did not pass type constraint "InvoiceType| +CreditType" (in $args->{"type"}) at /home/dpaikkos/spl/local/lib/perl +5/Test/More.pm line 741 # "InvoiceType|CreditType" requires that the value pass "Credi +tType" or "InvoiceType" # Undef did not pass type constraint "InvoiceType" # "InvoiceType" is a subtype of "Enum["ACCPAY","ACCREC"]" # "Enum["ACCPAY","ACCREC"]" requires that the value is def +ined # Undef did not pass type constraint "CreditType"

    I excel at leaving typos in my code but I am pretty sure there are none in the code so far. The coercions appear to work in a stand alone fashion but when used as a union, the 2nd Type does not appear to apply the coercion. If I swap the "CreditType" to be the first item, I find that the InvoiceType fails.

    I suspect I could use some kind of named parameterized coercion and `plus_coercions` but I hit this snag and haven't been able to move forward.

    Does anyone have any insights into what I'm doing wrong?

    Thanks in advance
WebPerl in a Progressive Web App?
1 direct reply — Read more / Contribute
by LanX
on Mar 06, 2026 at 08:52
    Hi

    Is it possible to run WebPerl inside a PWA?

    Hence effectively running Perl inside an app which can be installed on Android, Win, Linux?

    Has it been attempted yet?

    What are the results?

    Does it reduce the startup time of Perl because it's running hot in the background?

    Cheers Rolf
    (addicted to the Perl Programming Language :)
    see Wikisyntax for the Monastery

Tieing STDERR to a textbox causes the IPC::Run start function to fail
2 direct replies — Read more / Contribute
by CrashBlossom
on Mar 05, 2026 at 20:28
    Greetings Monks, I am running strawberry perl 5.30 under windows 11.

    When the program below reaches the start function, it fails with the seemingly nonsensical error "Can't locate auto/Tk/ROText/FILENO.al". Tieing only STDOUT to the same widget is no problem.

    Does anyone have any insight as to what is happening here?

    use warnings; use strict; use IPC::Run qw(start pump finish timeout); use Tk; require Tk::ROText; my $mw = MainWindow->new(-title => " NON BLOCKING"); my $outw = $mw->Scrolled('ROText', -font => "{Courier New} 10 bold", -background => 'DarkBlue', -foreground => 'OldLace', -scrollbars => 'se', -wrap => 'none', -width => 100, -height => 10, )->pack(-fill => "both", -expand => 1); + # tie *STDOUT, 'Tk::Text', $outw; tie *STDERR, 'Tk::Text', $outw; my ($in, $out, $err) = ('', '', ''); my $h; if (! defined(eval { $h = start ['cmd.exe', '/c', 'dir'], \$in, \$out, + \$err; })) { print "\nStart failed: $@\n"; } while($h->pumpable) { $h->pump; print $out; $out = ''; } $h->finish; MainLoop;
Meditations
SVG - what were they smoking?
2 direct replies — Read more / Contribute
by afoken
on Mar 10, 2026 at 06:42

    Just another rant ...

    Yesterday, I improved a small helper script that reads an SVG file and converts that to code fragments for drawing lines and texts. (The target does not support displaying and manipulating SVG images the way I need it.) The script was (and still is) too stupid for all SVG features, because it only needs to process one image, supplied by our client.

    The first image was years old, all coordinates were absolute. The image was changed, using a different version of the image editor, and suddenly, coordinates were relative. So I had to change the script. Wash, rinse, repeat. Yesterday, the script (and I) learned about horizontal and vertical line shortcuts, and shorcuts for cubic bezier curves. And about the completely INSANE way of representing paths in SVG.

    SVG is structured. It's XML after all, so you can group elements, give each element an ID, apply CSS. Great. And all the code you need for that is already implemented. It's just XML.

    You want a rectangle, green with a red border?

    <rect x="10" y="20" width="42" height="8" stroke="#ff0000" stroke-widt +h="2" fill="#00ff00" />

    A circle is as easy:

    <circle cx="10" cy="20" r="8" stroke="#ff0000" stroke-width="2" fill=" +#00ff00" />

    The same principle also applies for text, elipse, polygon and more.

    And then, there is something similar to Logo turtle graphics a.k.a. paths. There is an implicit current point, which is the starting point for the next command, and there are commands: Move to, line to, curve to, close path.

    How would you expect to see that in an XML-based vector image format? Like this:

    <path x="50" y="50" stroke="#ff0000" stroke-width="2" fill="#00ff00"> <lineto x="75" y="75" /> <lineto x="75" y="25" /> <closepath /> </path>

    XML, like all other elements, testable, parseable by any XML parser?

    Dream on! It looks like this:

    <path d="M396.73,645.98c-49.05,43.57-88.42,71.92-118.1,85.05-1.85.43-1 +7.07,11.54-45.26-.97-9.7-2.33-78.64-37.77-123.94-89.59,0,0-39.21-47.6 +6-50.48-134.8-7.51-58.09-13.85-106.3-19-144.64-14.55-30.82-24.76-38.5 +3-30.62-23.11-3.7,22.95,16.29,117.5,21.48,128.86"/>

    No, there was no cat running over the num pad. That how SVG represents paths. In a f*ing string looking more like a historic modem command than anything structured.

    Yes, there is structure. Upper and lower case letters followed by zero or more numbers. The letters are commands, the numbers are the arguments for the commands. Upper case letters indicate absolute coordinates, lower case letters indicate relative coordinates relative to the end point of the previous command.

    "But -1.85.43 does not look like a number" you say? Right! Its not a number, its two numbers, -1.85 and 0.43.

    "And why are there commas between some numbers, and no commas between other numbers?" Well, the comma is there if there is no implicit way to tell apart two numbers. It could also be a space. A negative number may simply be appended to another number, as for the reader it must be obvious that a "-" can't be within a number, so it must start a new number. The same rule also allows pasting a number n > 0 and n < 1 to be appended without its leading "0" to a non-integer number. It must be obvious for the reader that a non-integer number can not contain two ".", so the second one must start a second number.

    This garbage can be expressed as BNF: https://www.w3.org/TR/SVG11/paths.html#PathDataBNF

    To make sense of that number garbage, you basically have to take as much characters as possible that form a number, take that as an argument, and look for the next one. Whitespace and commas may be used to separate numbers.

    More nonsense?

    There is a "lineto" command (L/l) that expects pairs of numbers (coordinates) as arguments. There is a shortcut for horizontal lines ("H" or "h") that accepts only x coordinates, y is implicit from the end point of the previous command. And there is a shortcut for vertical lines ("V" or "v") that accepts only y coordinates. Both H/h and V/v accept MORE THAN ONE ARGUMENT in case you might want to draw two, three, four or ten succeeding horizontal (or vertical) lines.

    The "moveto" command (M/m) expects pairs (PLURAL!) of numbers (coordinates). It moves to the first x-y-position, then switches to "lineto" mode, and all but the first two numbers passed to "moveto" acutally behave as if passed to lineto. "M 1 2 3 4 6 5" is exactly equivalent to "M 1 2 L 3 4 6 5".

    Then there is cubic Bézier curves. The commands C/c start at the end of the previous command, and expect groups (PLURAL!) of six numbers, coordinates of two control points and an end point to draw the curve. Each group of six numbers draws one curve. There is also a shortcut command "S/s" that expects groups (PLURAL!) of only four numbers, each group specifying only the second control point and the end point. The first control point is either "the reflection of the second control point on the previous command relative to the current point" (the end point of the previous curve), if the previous command was a cubic Bézier curve command, or the end point of the previous command if the previous command was not a cubic Bézier curve.

    SVG also has quadratic Bézier curve commands, Q/q for the full spec, and T/t as shortcut. The same madness.

    Note that a command named "E" or "e" would cause problems, because numbers may be given in exponential notation: Is "M0-1.2E3,0" the start of a move command with arguments 0, -1.2E+3, 0 or is it a move command with arguments 0 and -1.2 and an E command with arguments 3 and 0? It must be the former, because numbers must be greedily extracted. So if you want an E command, it needs whitespace in front of the E. "M0-1.2 E3,0" is clearly moveto 0, -1.2 followed by E 3, 0.

    The SVG spec fights for single bytes in paths, by omitting sepeators for numbers and by nonsense shortcut commands, all in a format that is horrible bloated and repetitive. And the result makes all XML tools completely unusable for paths. XML just sees a string attribute with no more structure.

    WHAT WERE THEY SMOKING?

    Alexander

    --
    Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (2)
As of 2026-03-11 19:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.