I have a perlmodule.pm with authorize, post_auth blocks. Took the code from Freeradius example.pl

perlmodule.pm

#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software
#  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
#
#  Copyright 2002  The FreeRADIUS server project
#  Copyright 2002  Boian Jordanov <bjordanov@orbitel.bg>
#

#
# Example code for use with rlm_perl
#
# You can use every module that comes with your perl distribution!
#
# If you are using DBI and do some queries to DB, please be sure to
# use the CLONE function to initialize the DBI connection to DB.
#

use strict;
use warnings;

# use ...
use Data::Dumper;

# Bring the global hashes into the package scope
our (%RAD_REQUEST, %RAD_REPLY, %RAD_CHECK, %RAD_STATE, %RAD_PERLCONF);

# This is hash wich hold original request from radius
#my %RAD_REQUEST;
# In this hash you add values that will be returned to NAS.
#my %RAD_REPLY;
#This is for check items
#my %RAD_CHECK;
# This is the session-sate
#my %RAD_STATE;
# This is configuration items from "config" perl module configuration section
#my %RAD_PERLCONF;

# Multi-value attributes are mapped to perl arrayrefs.
#
#  update request {
#    Filter-Id := 'foo'
#    Filter-Id += 'bar'
#  }
#
# This results to the following entry in %RAD_REQUEST:
#
#  $RAD_REQUEST{'Filter-Id'} = [ 'foo', 'bar' ];
#
# Likewise, you can assign an arrayref to return multi-value attributes

#
# This the remapping of return values
#
use constant {
    RLM_MODULE_REJECT   => 0, # immediately reject the request
    RLM_MODULE_OK       => 2, # the module is OK, continue
    RLM_MODULE_HANDLED  => 3, # the module handled the request, so stop
    RLM_MODULE_INVALID  => 4, # the module considers the request invalid
    RLM_MODULE_USERLOCK => 5, # reject the request (user is locked out)
    RLM_MODULE_NOTFOUND => 6, # user not found
    RLM_MODULE_NOOP     => 7, # module succeeded without doing anything
    RLM_MODULE_UPDATED  => 8, # OK (pairs modified)
    RLM_MODULE_NUMCODES => 9  # How many return codes there are
};

# Same as src/include/log.h
use constant {
    L_AUTH         => 2,  # Authentication message
    L_INFO         => 3,  # Informational message
    L_ERR          => 4,  # Error message
    L_WARN         => 5,  # Warning
    L_PROXY        => 6,  # Proxy messages
    L_ACCT         => 7,  # Accounting messages
    L_DBG          => 16, # Only displayed when debugging is enabled
    L_DBG_WARN     => 17, # Warning only displayed when debugging is enabled
    L_DBG_ERR      => 18, # Error only displayed when debugging is enabled
    L_DBG_WARN_REQ => 19, # Less severe warning only displayed when debugging is enabled
    L_DBG_ERR_REQ  => 20, # Less severe error only displayed when debugging is enabled
};

#  Global variables can persist across different calls to the module.
#
#
#   {
#    my %static_global_hash = ();
#
#       sub post_auth {
#       ...
#       }
#       ...
#   }


# Function to handle authorize
sub authorize {
    # For debugging purposes only
#   &log_request_attributes;

    # Here's where your authorization code comes
    # You can call another function from here:
    &test_call;

    return RLM_MODULE_OK;
}

# Function to handle authenticate
sub authenticate {
    # For debugging purposes only
#   &log_request_attributes;

    if ($RAD_REQUEST{'User-Name'} =~ /^baduser/i) {
        # Reject user and tell him why
        $RAD_REPLY{'Reply-Message'} = "Denied access by rlm_perl function";
        return RLM_MODULE_REJECT;
    } else {
        # Accept user and set some attribute
        if (&radiusd::xlat("%{client:group}") eq 'UltraAllInclusive') {
            # User called from NAS with unlim plan set, set higher limits
            $RAD_REPLY{'h323-credit-amount'} = "1000000";
        } else {
            $RAD_REPLY{'h323-credit-amount'} = "100";
        }
        return RLM_MODULE_OK;
    }
}

# Function to handle preacct
sub preacct {
    # For debugging purposes only
#   &log_request_attributes;

    return RLM_MODULE_OK;
}

# Function to handle accounting
sub accounting {
    # For debugging purposes only
#   &log_request_attributes;

    # You can call another subroutine from here
    &test_call;

    return RLM_MODULE_OK;
}

# Function to handle checksimul
sub checksimul {
    # For debugging purposes only
#   &log_request_attributes;

    return RLM_MODULE_OK;
}

# Function to handle pre_proxy
sub pre_proxy {
    # For debugging purposes only
#   &log_request_attributes;

    return RLM_MODULE_OK;
}

# Function to handle post_proxy
sub post_proxy {
    # For debugging purposes only
#   &log_request_attributes;

    return RLM_MODULE_OK;
}

# Function to handle post_auth
sub post_auth {
    # For debugging purposes only
#   &log_request_attributes;

    return RLM_MODULE_OK;
}

# Function to handle xlat
sub xlat {
    # For debugging purposes only
#   &log_request_attributes;

    # Loads some external perl and evaluate it
    my ($filename,$a,$b,$c,$d) = @_;
    &radiusd::radlog(L_DBG, "From xlat $filename ");
    &radiusd::radlog(L_DBG,"From xlat $a $b $c $d ");
    local *FH;
    open FH, $filename or die "open '$filename' $!";
    local($/) = undef;
    my $sub = <FH>;
    close FH;
    my $eval = qq{ sub handler{ $sub;} };
    eval $eval;
    eval {main->handler;};
}

# Function to handle detach
sub detach {
    # For debugging purposes only
#   &log_request_attributes;
}

#
# Some functions that can be called from other functions
#

sub test_call {
    # Some code goes here
}

sub log_request_attributes {
    # This shouldn't be done in production environments!
    # This is only meant for debugging!
    for (keys %RAD_REQUEST) {
        &radiusd::radlog(L_DBG, "RAD_REQUEST: $_ = $RAD_REQUEST{$_}");
    }
}

sub my_custom_function {
    my $CustomAttribute = 0;
    return $CustomAttribute;

}

In the above code I created a subroutine my_custom_function which holds the variable with hard-coded value.

I want to read this variable's value in sites-available/default file to compare the values.

I'm trying to refer the variable in below way

sites-available/default

if ("%{CustomAttribute}" == 0) {
#####Do Something
}

I've additionally added CustomAttribute to my freeradius dictionary as well.

ATTRIBUTE       CustomAttribute         17270           integer

While performing radtest I get below error when radius reaching the if block I added in sites-available/default file.

Output from radiusd -X

(0) Tue May 14 18:22:27 2024: Debug:     elsif ("%{CustomAttribute}" == 0) {
(0) Tue May 14 18:22:27 2024: ERROR:     Failed retrieving values required to evaluate condition

Can someone show me the right way to retrieve this variable from the perlmodule to compare it in sites-available/default file under authorize block?

Fix HTTP and Books links

Perl commits on GitHub

Published by rwp0 on Thursday 16 May 2024 00:10

Fix HTTP and Books links

Update some obsolete Perl book URLs.  Convert some HTTP links to HTTPS.
Wrap links in `L<>`.

Committer: Resolve merge conflicts in pod/perllocale.pod.

For: https://github.com/Perl/perl5/pull/22186

Perl Dancer2 psgi app with Starman fails Stripe payment

Perl questions on StackOverflow

Published by user1742494 on Wednesday 15 May 2024 23:31

I'm at the very last stages of testing a webapp before making it live but am having problems with the app using the Stripe API. When the app is run standalone:

plackup -p 5000 bin/app.psgi

it does everything fine as expected. It goes through it's paces, successfully completes the Stripe test payment and there are no unexpected log messages. When I try to run it with the perl server Starman:

plackup -s Starman -a bin/app.psgi -l localhost:5000

everything is fine until I get to the Stripe payment portion. It usually goes through the process (but occasionally fails at other JSON calls) but after the payment is completed it fails to retrive the checkout session with the supplied session id:

Stripe API: GET /v1/checkout/sessions/:id

In this case I'm using the perl module Business::Stripe, this is where it fails:

#   my $session = $stripe->api( 'get', 'checkout/sessions', $session_id );
    my $session = $stripe->api( 'get', 'checkout/sessions', 'id' => $session_id );

Error log:

[HWCal:82368] error @2024-05-15 16:54:08> Route exception: malformed JSON string, neither array, object, number, string or atom, at character offset 0 (before "(end of string)") at /usr/share/perl5/vendor_perl/Business/Stripe.pm line 587. in /usr/local/share/perl5/5.36/Dancer2/Core/App.pm l. 1516

The stripe object and session_id are valid but it dies there with nothing happening afterward. The commented out line worked just fine when run without Starman. I just changed it because the docs say it wants a hash there. The plackup/Starman version doesn't work with either. Interestingly the app had to earlier create a checkout session object using post which it did successfully. I think the problem has to do with Starman's way of working with JSON but I can't find anything on it. I'm at a loss and would appreciate any ideas for troubleshooting this issue.

I tried double checking the JSON code to omit trailing commas and other things mentioned in the browser console at: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/JSON_bad_parse

Nothing seemed to help.

perllocale: Update for 5.40 state of affairs

Perl commits on GitHub

Published by khwilliamson on Wednesday 15 May 2024 23:01

perllocale: Update for 5.40 state of affairs

This makes corrections, and additions

perl regex negative lookahead replacement with wildcard

Perl questions on StackOverflow

Published by David Peng on Wednesday 15 May 2024 22:25

Updated with real and more complicated task:

The problem is to substitute a certain pattern to different result with or without _ndm.

The input is a text file with certain line like:

/<random path>/PAT1/<txt w/o _ndm>
/<random path>/PAT1/<txt w/ _ndm>

I need change those to

/<ramdom path>/PAT1/<sub1>
/<random path>/PAT1/<sub2>_ndm

I wrote a perl command to process it:

perl -i -pe 's#PAT1/.*_ndm#<sub2>_ndm#; s#PAT1/.*(?!_ndm)#<sub1>#' <input_file>

However, it doesn't work as expected. the are all substituted to instead of _ndm.


Original post:

I need use shell command to replace any string not ending with _ndm to another string (this is an example):

abc
def
def_ndm

to

ace
ace
def_ndm

I tried with perl command

perl -pe 's/.*(?!_ndm)/ace/'

However I found wildcard didn't work with negative lookahead as my expected. Only if I include wildcard in negative pattern, it can skip def_ndm correctly; but because negative lookahead is a zero length one, it can't replace normal string any more.

any idea?

Confirming The LPW 2024 Venue & Date

blogs.perl.org

Published by London Perl Workshop on Wednesday 15 May 2024 17:48

We're happy to confirm the venue and date of this year's London Perl & Raku Workshop.

When: Saturday 26th October 2024
Where: The Trampery, 239 Old Street, London EC1V 9EY

This year's workshop will be held at The Trampery, at Old Street. A dedicated modern event space in central London. We have hired both The Ballroom and The Library; allowing us to run a main track for up to 160 attendees, and second smaller track for up to 35 attendees.

The Trampery in Old Street is located a two minute walk from the Northern Line's Old Street tube station in central London. The Northern Line has stops at most of the major train stations in London, or trivial links to others, so we recommend taking the tube to get to the venue.

If you haven't already, please signup and submit talks using the official workshop site: https://act.yapc.eu/lpw2024/

Thanks to this year's sponsors, without whom LPW would not happen:

If you would like to sponsor LPW then please have a look at the options here: https://act.yapc.eu/lpw2024/sponsoring.html

PWC 269 Two of Us Distributing Elements

dev.to #perl

Published by Bob Lied on Wednesday 15 May 2024 14:08

You and I have memories, longer than the road that stretches out ahead. Remember when refactoring was a Big Deal? Let's do some of that this week.

Two of Us Lyrics Music

Task 2: Distribute Elements

You are given an array of distinct integers, @ints.

Write a script to distribute the elements as
described below:

1) Put the 1st element of the given array to
a new array @arr1.
2) Put the 2nd element of the given array to
a new array @arr2.

Once you have one element in each arrays,
@arr1 and @arr2, then follow the rule below:

If the last element of the array @arr1 is greater
than the last element of the array @arr2, then
add the first element of the given array to @arr1,
otherwise to the array @arr2.

When done distribution, return the concatenated
arrays, @arr1 and @arr2.

Example 1

  • Input: @ints = (2, 1, 3, 4, 5)
  • Output: (2, 3, 4, 5, 1)

    • 1st operation: Add 2 to @arr1 = (2)
    • 2nd operation: Add 1 to @arr2 = (1)
    • 3rd operation: Now the last element of @arr1 is greater than the last element of @arr2, so add 3 to @arr1 = (2, 3).
    • 4th operation: Again the last element of @arr1 is greater than the last element of @arr2, add 4 to @arr1 = (2, 3, 4)
    • 5th operation: Finally, the last element of @arr1 is again greater than the last element of @arr2, add 5 to @arr1 = (2, 3, 4, 5)
    • Now we have two arrays: @arr1 = (2, 3, 4, 5) and @arr2 = (1)
    • Concatenate the two arrays and return the final array: (2, 3, 4, 5, 1).

Phase 1, in which Doris gets her oats

That's a very prescriptive specification and example. We could hardly do anything else.

sub distElem(@ints) 
{
    my @arr1 = shift @ints; 
    my @arr2 = shift @ints; 
    while ( defined(my $n = shift @ints) )
    {
        if ( $arr1[-1] > $arr2[-1] ) {
            push @arr1, $n;
        } else {
            push @arr2, $n;
        }
    }
    return [ @arr1, @arr2 ];
}

Perl notes:

  • We're using up the @ints array by shifting off one element at a time. Numbers could be zero, and we don't want that interpreted as false, so the accurate check is to look for the undef when the array becomes empty.
  • Perl can index from the end by using negative offsets. We don't have to do any bookkeeping about the lengths of the arrays.

Sunday driving, not arriving

It irks me to have the two variables named arr1 and arr2. What is this, BASIC? It's a list of two arrays, so let's do that refactoring.

sub distElem(@ints) 
{
    my @arr = ( [shift @ints], [shift @ints] );
    while ( defined(my $n = shift @ints) )
    {
        if ( $arr[0][-1] > $arr2[1][-1] ) {
            push @{$arr[0]}, $n;
        } else {
            push @{$arr[1]}, $n;
        }
    }
    return [ $arr[0]->@*, $arr[1]->@* ];
}

Perl notes:

  • We now have an array of two references to arrays, so we see array de-referencing syntax. The first argument to push needs to be an array, so the @{...} turns the reference into an array. In the return statement, I use newer-style postfix de-referencing.

Burning matches, lifting latches

Now I'm annoyed by that if statement. We only have to choose between 0 and 1, and we have a condition that will be either true or false. Zero, one; false, true. Po-tay-to, po-tah-to. Let's use that condition to make an index.

sub distElem(@ints) 
{
    my @arr = ( [shift @ints], [shift @ints] );
    while ( defined(my $n = shift @ints) )
    {
        my $which = ( $arr[0][-1] <= $arr[1][-1] );
        push @{$arr[$which]}, $n;
    }
    return [ $arr[0]->@*, $arr[1->@*} ];
}

Perl notes:

  • True and false values will be interpreted as 1 and zero, respectively, when used in an arithmetic context.
  • I changed the test from > to <= so that the array order is the same.

Chasing paper, getting nowhere

Introducing the $which variable seems arbitrary. Let's put that in-line.

sub distElem(@ints) 
{
    my @arr = ( [shift @ints], [shift @ints] );
    while ( defined(my $n = shift @ints) )
    {
        push @{$arr[ $arr[0][-1] <= $arr[1][-1 ]}, $n;
    }
    return [ $arr[0]->@*, $arr[1->@*} ];
}

Wearing raincoats, standing solo

Why am I chewing up the @ints array with shifts? Let's just iterate over it.

sub distElem(@ints) 
{
    my @arr = ( [shift @ints], [shift @ints] );
    push @{$arr[ $arr[0][-1] <= $arr[1][-1 ]}, $_ for @ints;
    return [ $arr[0]->@*, $arr[1->@*} ];
}

We're on our way home, we're going home

One last thing: can we make it do reasonable things when the @ints array has 0 or 1 elements? Currently, that inital shift to initialize @arr would put an undef value into the lists. Let's account for the possibility.

sub distElem(@ints)
{
    my @arr = ( [ (shift @ints) // () ], [ (shift @ints) // () ] );

    push @{$arr[ ( $arr[0][-1] <= $arr[1][-1] ) ]}, $_ for @ints;

    return [ $arr[0]->@*, $arr[1]->@* ];
}

Perl notes:

  • shift on an empty array will yield undef, but we want an empty list in that case.
  • The // operator is really useful for checking defined-ness. In the old days, code was littered with if (defined(...)) tests.

The long and winding road (oops, wrong song)

That was the process I used to get from 11 lines to 3. Of course, there were unit tests executed at every step. The final code, including tests is in GitHub

Confirming The LPW 2024 Venue & Date

dev.to #perl

Published by Lee J on Wednesday 15 May 2024 12:44

We're happy to confirm the venue and date of this year's London Perl & Raku Workshop.

  • When: Saturday 26th October 2024
  • Where: The Trampery, 239 Old Street, London EC1V 9EY

This year's workshop will be held at The Trampery, at Old Street. A dedicated modern event space in central London. We have hired both The Ballroom and The Library; allowing us to run a main track for up to 160 attendees, and second smaller track for up to 35 attendees.

The Trampery in Old Street is located a two minute walk from the Northern Line's Old Street tube station in central London. The Northern Line has stops at most of the major train stations in London, or trivial links to others, so we recommend taking the tube to get to the venue.

If you haven't already, please signup and submit talks using the official workshop site: https://act.yapc.eu/lpw2024/

Thanks to this year's sponsors, without whom LPW would not happen:

If you would like to sponsor LPW then please have a look at the options here: https://act.yapc.eu/lpw2024/sponsoring.html

Confirming The LPW 2024 Venue & Date

r/perl

Published by /u/leejo on Wednesday 15 May 2024 12:35

How can I mock Perl's unlink function?

Perl questions on StackOverflow

Published by Robert on Wednesday 15 May 2024 08:38

I want to mock Perl's unlink to test that my code deletes the right files. Based on this question and its answers and this other question and its answers, I tried:

use strict;
use warnings;
use subs 'unlink';
  
sub mock_unlink {
    use Data::Printer; p @_;
    return;
}     

BEGIN {
    no warnings qw/redefine/;
    *CORE::GLOBAL::unlink = \mock_unlink;
    # *unlink = \mock_unlink;
    use warnings;
}
          
unlink "some file";

But when I run this, my mocked function does get called, but the list of arguments is empty. I also get a warning that unlink is undefined.

$ perl mcve.pl
[]
Undefined subroutine &main::unlink called at mcve.pl line 17.

I expected it to print

["some file"]

I've tried the commented out line *unlink = \mock_unlink; instead, but that didn't change anything.

How do I need to mock unlink to check what files my code tries to delete?

About Perl Programming

Perl on Medium

Published by Vcanhelpsu on Wednesday 15 May 2024 07:40

We have a file that need ascii characters translated to another ascii characters for formatting purposes. We have always used perl -pe or sed to be called externally in a system command within a perl script to do this.

However since we moved to Red Hat from AIX, we have noticed that perl -pe doesn't work as expected from within the perl script then it does from the command line.

system("cat $AlifeFile | perl -p -e 's/\|.*MSH/\nMSH\|/g'| tr -d '\v'>> <outbound file name>");

Produces

MSH|
MSH|
MSH||
MSH|^
MSH|~
MSH|\
MSH|&
MSH||
MSH|A
MSH|-
MSH|L
MSH|i
MSH|f
MSH|e
MSH||
MSH||
MSH|I
MSH|D
MSH|X
MSH|_
MSH|T
MSH|E
MSH|S
MSH|_
MSH|C
MSH|H
MSH|G
MSH||
MSH||
MSH|2
MSH|0
MSH|2
MSH|4
MSH|0
MSH|5
MSH|0
MSH|9
MSH|1
MSH|3

if should be

MSH...
MSH...

when I am trying to replace \r034\r\v with a \n before the MSH segment in a HL7 message.

When I try that same system command but from a command line outside of the perl script it translates it correctly.

So why if I call it from the perl script inside a system command is it producing a different result then when I call that same code from a Red Hat Command Line?

Perl Weekly Challenge 269: Distribute Elements

blogs.perl.org

Published by laurent_r on Tuesday 14 May 2024 00:05

These are some answers to the Week 269, Task 2, of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a few days from now (on May 19, 2024 at 23:59). This blog post provides some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.

Task 2: Distribute Elements

You are given an array of distinct integers, @ints.

Write a script to distribute the elements as described below:

1) Put the 1st element of the given array to a new array @arr1. 2) Put the 2nd element of the given array to a new array @arr2.

Once you have one element in each arrays, @arr1 and @arr2, then follow the rule below:

If the last element of the array @arr1 is greater than the last element of the array @arr2 then add the first element of the given array to @arr1 otherwise to the array @arr2.

When done distribution, return the concatenated arrays. @arr1 and @arr2.

Example 1

Input: @ints = (2, 1, 3, 4, 5)
Output: (2, 3, 4, 5, 1)

1st operation:
Add 1 to @arr1 = (2)

2nd operation:
Add 2 to @arr2 = (1)

3rd operation:
Now the last element of @arr1 is greater than the last element
of @arr2, add 3 to @arr1 = (2, 3).

4th operation:
Again the last element of @arr1 is greate than the last element
of @arr2, add 4 to @arr1 = (2, 3, 4)

5th operation:
Finally, the last element of @arr1 is again greater than the last
element of @arr2, add 5 to @arr1 = (2, 3, 4, 5)

Now we have two arrays:
@arr1 = (2, 3, 4, 5)
@arr2 = (1)

Concatenate the two arrays and return the final array: (2, 3, 4, 5, 1).

Example 2

Input: @ints = (3, 2, 4)
Output: (3, 4, 2)

1st operation:
Add 1 to @arr1 = (3)

2nd operation:
Add 2 to @arr2 = (2)

3rd operation:
Now the last element of @arr1 is greater than the last element
of @arr2, add 4 to @arr1 = (3, 4).

Now we have two arrays:
@arr1 = (3, 4)
@arr2 = (2)

Concatenate the two arrays and return the final array: (3, 4, 2).

Example 3

Input: @ints = (5, 4, 3 ,8)
Output: (5, 3, 4, 8)

1st operation:
Add 1 to @arr1 = (5)

2nd operation:
Add 2 to @arr2 = (4)

3rd operation:
Now the last element of @arr1 is greater than the last element
of @arr2, add 3 to @arr1 = (5, 3).

4th operation:
Again the last element of @arr2 is greate than the last element
of @arr1, add 8 to @arr2 = (4, 8)

Now we have two arrays:
@arr1 = (5, 3)
@arr2 = (4, 8)

Concatenate the two arrays and return the final array: (5, 3, 4, 8).

Distribute Elements in Raku

We can hardly do anything else than just follow the procedure described in the task specification.

sub distribute-elements (@in is copy) {
    my @arr1 = shift @in;
    my @arr2 = shift @in;
    for @in -> $item {
        if @arr1[*-1] > @arr2[*-1] {
            push @arr1, $item;
        } else {
            push @arr2, $item;
        }
    }
    return (@arr1, @arr2).flat;
}
my @tests = <2 1 3 4 5>, <3 2 4>, <5 4 3 8>;
for @tests -> @test {
    printf "%-10s => ", "@test[]";
    say distribute-elements @test;
}

This program displays the following output:

$ raku ./distribute-elements.raku
2 1 3 4 5  => (2 3 4 5 1)
3 2 4      => (3 4 2)
5 4 3 8    => (5 3 4 8)

Distribute Elements in Perl

This is a port to Perl of the above Raku program.

use strict;
use warnings;
use feature 'say';

sub distribute_elements {
    my @arr1 = shift;
    my @arr2 = shift;
    for my $item (@_) {
        if ($arr1[-1] > $arr2[-1]) {
            push @arr1, $item;
        } else {
            push @arr2, $item;
        }
    }
    return "@arr1 @arr2";
}
my @tests = ( [<2 1 3 4 5>], [<3 2 4>], [<5 4 3 8>] );
for my $test (@tests) {
    printf "%-10s => ", "@$test";
    say distribute_elements @$test;
}

This program displays the following output:

$ perl ./distribute-elements.pl
2 1 3 4 5  => 2 3 4 5 1
3 2 4      => 3 4 2
5 4 3 8    => 5 3 4 8

Wrapping up

The next week Perl Weekly Challenge will start soon. If you want to participate in this challenge, please check https://perlweeklychallenge.org/ and make sure you answer the challenge before 23:59 BST (British summer time) on May 26, 2024. And, please, also spread the word about the Perl Weekly Challenge if you can.

Perl Weekly Challenge 269: Bitwise OR

blogs.perl.org

Published by laurent_r on Monday 13 May 2024 19:35

These are some answers to the Week 269, Task 1, of the Perl Weekly Challenge organized by Mohammad S. Anwar.

Spoiler Alert: This weekly challenge deadline is due in a few days from now (on May 19, 2024 at 23:59). This blog post provides some solutions to this challenge. Please don’t read on if you intend to complete the challenge on your own.

Task 1: Bitwise OR

You are given an array of positive integers, @ints.

Write a script to find out if it is possible to select two or more elements of the given array such that the bitwise OR of the selected elements has at least one trailing zero in its binary representation.

Example 1

Input: @ints = (1, 2, 3, 4, 5)
Output: true

Say, we pick 2 and 4, their bitwise OR is 6. The binary representation of 6 is 110.
Return true since we have one trailing zero.

Example 2

Input: @ints = (2, 3, 8, 16)
Output: true

Say, we pick 2 and 8, their bitwise OR is 10. The binary representation of 10 is 1010.
Return true since we have one trailing zero.

Example 3

Input: @ints = (1, 2, 5, 7, 9)
Output: false

First, we should state that the binary representation of an integer has a trailing zero if (and only if) it is an even number. Second, we should notice that a bitwise OR between two integers will yield an even number only if both numbers are even: if any of the two integers is odd (binary representation with a trailing 1), then the bitwise OR between them will also have a trailing 1 (and it will be odd).

To illustrate this, the following small Raku program performs a bitwise OR between all combinations of integers between 0 and 8:

say "\t", join " ", 0..8;
for 0..8 -> $i {
    say "$i\t", join " ", map { $i +| $_}, 0..8;
}

This program displays the following output:

        0 1 2 3 4 5 6 7 8
0       0 1 2 3 4 5 6 7 8
1       1 1 3 3 5 5 7 7 9
2       2 3 2 3 6 7 6 7 10
3       3 3 3 3 7 7 7 7 11
4       4 5 6 7 4 5 6 7 12
5       5 5 7 7 5 5 7 7 13
6       6 7 6 7 6 7 6 7 14
7       7 7 7 7 7 7 7 7 15
8       8 9 10 11 12 13 14 15 8

In other words, it will be "possible to select two or more elements of the given array such that the bitwise OR of the selected elements has least one trailing zero in its binary representation" if and only if there are at least two even integers in the input list. So, all we need to do is to count the number of even integers in the input list.

Bitwise OR in Raku

Based on the explanations above, we simply count the number of even numbers and return True if this count is two or more (and False otherwise).

sub bitwise-or (@in) {
    my @evens = grep { $_ %% 2 }, @in;
    return @evens.elems >= 2 ?? True !! False;
}

my @tests = (1, 2, 3, 4, 5), (2, 3, 8, 16), (1, 2, 5, 7, 9);
for @tests -> @test {
    printf "%-12s => ", "@test[]";
    say bitwise-or @test;
}

This program displays the following output:

$ raku ./bitwise-or.raku
1 2 3 4 5    => True
2 3 8 16     => True
1 2 5 7 9    => False

Bitwise OR in Perl

Based on the explanations above, we simply count the number of even numbers and return "True" if this count is two or more (and "False" otherwise).

use strict;
use warnings;
use feature 'say';

sub bitwise_or {
    my @evens = grep { $_ % 2 == 0} @_;
    return scalar @evens >= 2 ? "True" : "False";
}

my @tests = ([1, 2, 3, 4, 5], [2, 3, 8, 16], [1, 2, 5, 7, 9]);
for my $test (@tests) {
    printf "%-12s => ", "@$test";
    say bitwise_or @$test;
}

This program displays the following output:

$ perl  ./bitwise-or.pl
1 2 3 4 5    => True
2 3 8 16     => True
1 2 5 7 9    => False

Wrapping up

The next week Perl Weekly Challenge will start soon. If you want to participate in this challenge, please check https://perlweeklychallenge.org/ and make sure you answer the challenge before 23:59 BST (British summer time) on May 26, 2024. And, please, also spread the word about the Perl Weekly Challenge if you can.

Error in hash and it’s equivalence with the index of an array

r/perl

Published by /u/SamuchRacoon on Monday 13 May 2024 13:03

I’m sorry if the text is strange, but I cannot upload it with my laptop.

I want to repeat a process for every key in a hash, with numeric keys. So there are 3 possibilities, with 3 if, and each one compares the value of the index of an array, so that if that position eq to "sp", "sp2" or "sp3" it will search in a document some value so then it can be printed.

It doesn´t work and every times gives me only one value, i would like to get the values that correspond with the hash.

For example the hash could be %grupos=(1,'A',2,'G',3,'J')

and the array @ hibridaciones=("sp","sp2",sp3")

The document .txt (simplified) is:

HS0.32

CS0,77

CD0.62

CT0,59

C10,77

C20,62

C30,59

OS0.73

OD0,6

O10,73

O20,6

NS0.75

The code is:

@hibridaciones=("sp","sp2",sp3") %grupos=(1,'A',2,'G',3,'J') open (covalencia,"<", "cov.txt") or die "$!\n"; print keys %grupos; keys %grupos; foreach my $z (keys %grupos) { print "\n$z\n"; if (@hibridaciones[my $z-1] eq "sp") { while (my $line = <covalencia>) { if ( $line=~/^C1/) { $line =~s/C1//; $radio=$line; print "\n$radio"; } } } if (@hibridaciones[my $z-1] eq "sp2") { while (my $line = <covalencia>) { if ($line=~/^C2/) { $line =~s/C2//; $radio=$line; print "\n$radio"; } } } if (@hibridaciones[my $z-1] eq "sp3") { while (my $line = <covalencia>) { if ($line=~/^C3/) { $line =~s/C3//; $radio=$line; print "\n$radio"; } } } } close (covalencia);@hibridaciones=("sp","sp2",sp3") %grupos=(1,'A',2,'G',3,'J') open (covalencia,"<", "cov.txt") or die "$!\n"; print keys %grupos; keys %grupos; foreach my $z (keys %grupos) { print "\n$z\n"; if (@hibridaciones[my $z-1] eq "sp") { while (my $line = <covalencia>) { if ( $line=~/^C1/) { $line =~s/C1//; $radio=$line; print "\n$radio"; } } } if (@hibridaciones[my $z-1] eq "sp2") { while (my $line = <covalencia>) { if ($line=~/^C2/) { $line =~s/C2//; $radio=$line; print "\n$radio"; } } } if (@hibridaciones[my $z-1] eq "sp3") { while (my $line = <covalencia>) { if ($line=~/^C3/) { $line =~s/C3//; $radio=$line; print "\n$radio"; } } } } close (covalencia); 
submitted by /u/SamuchRacoon
[link] [comments]

Perl Weekly #668 - Perl v5.40

dev.to #perl

Published by Gabor Szabo on Monday 13 May 2024 09:21

Originally published at Perl Weekly 668

Hi there,

The latest Perl Steering Council weekly updates about the good progress in preparation of release of Perl v5.40. I can't wait to get my hand dirty with the new features.

London Perl Workshop is making good progress thanks to the hard work of Lee Johnson. As per the official website, we now have a Diamond Sponsor. I am hoping venue would be finalised soon. I would urge all Perl fans to register your interest in the event so that the organiser can plan the event better.

The upconing event, The Perl and Raku Conference in Las Vegas, is in demand. I get to hear a lot of preparation is underway to make it memorable experience for all attendees. I am going to miss the fun, unfortunately. I hope to join you all online if it is available.

Last but not least, you take extra care of yourself and your loved ones. Enjoy and celebrate Perl as always.

--
Your editor: Mohammad Sajid Anwar.

Announcements

This Week in PSC (147)

Good news is shared that Perl v5.40 is likely to be released on time in May. Hurray !!!

Maintaining Perl (Tony Cook) February 2024

Articles

Perl Toolchain Summit 2024 - Lisbon

Nice to hear the work done by CPANSec Group. We are happy to see members are actively working on the security aspect.

MariaDB 10 and Perl DBIx::Class::Schema::Loader

Interesting topic brought to the discussion table with regard to the use of DBIx::Class and it's family. It is thorough discussion and not just scratch the surface.

Making a Super Cal if Rage Will Stick Ex Paella Down Us

Calendar is one topic that has been discussed plenty of times and we have loads of different implmentation available on CPAN. Saif is bringing a new flavour, go check it out.

The Weekly Challenge

The Weekly Challenge by Mohammad Sajid Anwar will help you step out of your comfort-zone. We pick one champion at the end of the month from among all of the contributors during the month.

The Weekly Challenge - 269

Welcome to a new week with a couple of fun tasks "Bitwise OR" and "Distribute Elements". If you are new to the weekly challenge then why not join us and have fun every week. For more information, please read the FAQ.

RECAP - The Weekly Challenge - 268

Enjoy a quick recap of last week's contributions by Team PWC dealing with the "Magic Number" and "Number Game" tasks in Perl and Raku. You will find plenty of solutions to keep you busy.

TWC268

A new CPAN module introduced Data::Show. Time to explore more about it. Thanks for sharing.

Numerous Numbers

Smart match of Raku is really cool. The post shares the use of smart match. Highly recommended.

Games Numbers Play

I love the varieties of different level of solutions. Start with simple and then move upward to make it more elegant. Great work.

Perl Weekly Challenge: Week 268

Ever wanted to implement Z- operator in Perl? Well it is already done and shared. Just check it out yourself.

Sorting This and That

My personal favourite PDL is in the game again. Thanks for sharing knowledge with us.

Perl Weekly Challenge 268: Magic Numbers

Reduction operator of Raku is one of the most powerful operator. Please checkout the post to see how it can be used.

Perl Weekly Challenge 268: Number Game

Handy Raku REPL is showing off the power. You really don't want to skip it. Thanks for sharing.

arrays and slices

Another Raku fan talking about rotor of Raku. I wonder if this can be reproduced this in Perl?

Perl Weekly Challenge 268

Master of one-liner in Perl, sharing experimental for_list. Time to explore more about it soon. Well done and keep it up.

Perl Magic Games

Task analysis is the top level and very engaging. Thanks for sharing the knowledge with us.

Let’s do the Numbers!

Short and compact solutions in Perl, Raku and Python. Plenty to keep you busy. You get to listen to music as bonus.

Magic and scrambled numbers

Peter finally gave in and created one-liner in Perl. It is so much fun to see how powerful it is.

The Weekly Challenge - 268

Well documented solutions with smart use of CPAN module. Well done, keep it up great work.

The Weekly Challenge #268

I noticed the zip6 is mentioned in the blog post but in code, pairwise is used. Interesting, zip6 is new to me, though.

If the Game is Magic, Where's My Number?

One liner in Python and PostScript. Bonus for this week is the introduction to Crystal. Keep it up great work.

The magical number game

Is it possible to have multiple return types in Python? I didn't know that, I liked how it is perfectly used here. Thanks for sharing the magic with us.

Rakudo

2024.19 Behaviorally Constrained

Weekly collections

NICEPERL's lists

Great CPAN modules released last week;
StackOverflow Perl report.

You joined the Perl Weekly to get weekly e-mails about the Perl programming language and related topics.

Want to see more? See the archives of all the issues.

Not yet subscribed to the newsletter? Join us free of charge!

(C) Copyright Gabor Szabo
The articles are copyright the respective authors.

INSTALL: threads and ithreads currently synonymous

Perl commits on GitHub

Published by jkeenan on Monday 13 May 2024 01:49

INSTALL: threads and ithreads currently synonymous

As suggested by Sevan Janiyan in GH #21886.

The new Carp::Object module is an object-oriented replacement for Carp or Carp::Clan. What is the point ? Well, here is some motivation.

The Carp module and its croak function have been around since perl 5.000. Errors can then be reported from the perspective of where the module was called, instead of the line where the error is raised. This excellent example from Mastering Perl explains why this is useful :

1	package Local::Math {
2	  use Carp qw(croak);
3	  sub divide {
4	    my( $class, $numerator, $denominator ) = @_;
5	    croak q(Can't divide by zero!) if $denominator == 0;
6	    $numerator / $denominator;
7	  }
8	}

Dieing at line 5 would be meaningless : it would report a division by zero at line 5, but the reason for that is not at line 5, it is in the calling program where a 0 value is passed as $denominator to the divide method. When using croak instead of die, all stack frames within the Local::Math package are skipped, and the error is reported at the caller’s level.

So far so good, but what happens if package Local::Math is just an internal member of a bigger family? Imagine we have a Local::ScalarOps package which delegates some operations to Local::Math, including the divide method. Then croak will report the error at the Local::ScalarOps level, not at the original caller’s level. 

Fortunately, there is a way to tell Carp to ignore other packages as well :

  use Carp qw(croak);
  our @CARP_NOT = qw(Local::ScalarOps Local::Foo Some::Other::Package);

This is much better. The @CARP_NOT array can even be locally modified if some places in the module need a different croaking behaviour. However, if your family of modules is large, it can be cumbersome to enumerate them all, and there is a risk to omit to upgrade the list if you later add new modules to the family.

Carp::Clan offers a solution : the family (the “clan”) of modules can be described through a regexp :

  use Carp::Clan qw(^(Local::|Some::Other::Package));

The regexp is passed as string within the import list. A croak function similar to Carp::croak is implicitly exported (together with other functions carp, confess and cluck). This can flexibly handle clans of modules in a common namespace. But now the clan of modules is specified at compile time : it cannot be dynamically modified. This is probably good enough for most common uses, but for edge cases it can be an annoying limitation.

So here comes Carp::Object : at each croaking site you can tune various aspects of the croaking behaviour (rules for skipping stack frames, customized callbacks for rendering stack frames, etc.) :

  use Carp:Object ();
  my $carper = Carp::Object->new(%options);
  ..
  check_good_condition() or $carper->croak(“there is a problem”);

Possible options are described in the documentation. Internally, stack frames are rendered through Devel::StackTrace, so all Devel::StackTrace options are also available.

Admittedly, the object-oriented idiom is more verbose, but if you prefer there is also a functional API compatible with traditional Carp for hiding the details.

For a complete use case, here is the situation that initially motivated this work. Consider a middleware framework like DBIx::DataModel, an object-relational mapping (ORM) framework that sits between the DBI layer and the application layer. The ORM uses a whole clan of modules in namespaces DBIx::DataModel::* and SQL::Abstract::*. But this is an extensible framework, so clients may well supply their own classes in-between, like for example a custom My::Local::Statement that extends the DBIx::DataModel::Statement class. Therefore the whole clan of modules can only be known at runtime, when the DBIx::DataModel::Schema is instantiated. With Carp::Object we can tune the croaking behaviour so that all ORM modules, including user-supplied modules, are skipped when a SQL error occurs. Details are in the _handle_SQL_error method.

Finally, Carp::Object also offers two additional improvements over Carp or Carp::Clan :

  1. if the croak method receives an exception object instead of a plain string, it just stringifies the object and then behaves as usual. By contrast, Carp or Carp::Clan do not know how to handle exception objects : they just die without performing the ordinary stack frames mechanics. This can be quite annoying when your module doesn’t know what kinds of errors can be raised by the underlying layers.
  2. Carp::Object attempts to infer if some calls in the stack are method calls instead of subroutine calls. When this is the case, the message line for that stack frame is rewritten to make it apparent that this is a method call.

I hope that Carp::Object can be useful to you. Do not hesitate to raise issues if you find bugs.

Making a Super Cal if Rage Will Stick Ex Paella Down Us

blogs.perl.org

Published by Saif on Sunday 12 May 2024 14:12

Something I am not good at

The paella must be possibly the worst national dish ever created, I thought to myself as I looked at the charred remains in my pan. It is as if the mind of some ancient Spanish conquistador, returned from his conquests abroad feeling hungry and unfulfilled, dreamt of bringing byriani to Spain, but in the midst of pillaging had forgotten to take culinary notes.

"How difficult can it be, Jose?" the weary warrior muses,
"Yeah, yeah, its just rice and meat, innit", says his Catalan colleague coming from the Spanish equivalent of Birmingham.
"We could use something flavourless, amorphous and chewy, like mussels, instead of meat",
"Whoaaah, nice,",
"And langoustines...",
"langa-what?",
"I know, right? Just throw them all in, don't bother shelling them",
"Raphael has some tomatoes he doesn't need for pelting passing pedestrians",
"Ahh...the flavours", fanning the flames as the smell of their concoction cooking brings back fond memories of far-away burning villages.

As I proudly presented my still smouldering efforts on the table, I am met with quizzical glances.

"What is it?" asked Mrs Saif, "I mean I can see what it is, but what is meant to be?",
"Its Spanish! Paella!", I exclaimed, "It's what Nadal, Ballesteros, and Ronaldo eat, guys. Come on, tuck in!",
The kids were not too sure, "Looks like your byriani" said one, encouragingly.
"Ronaldo is Portuguese," said another hoping to distract while passing her food to the dog who knew better.
"Look, why don't we order Mexican" said Mrs Saif kindly, "and you can try something you are goo.. err.. not so bad at."

Something I am not as bad at

Failure, I am used to. Under appreciation, I accept as the condemned accepts the noose. If I can divert my attention to coding instead of cooking, I may perhaps have less cause for despondency. But for me, the two streams of activity, cooking or coding, have the same triggers, and very often the same outcomes. Some one says: "You can't cook", outcome: paella. "You can't do this in Perl", outcome: more burnt offerings, sacrificing time and sanity, yielding an unrecognisable, unconsumable concoction for presentation to a community that never wanted it in the first place.

So when one person on Reddit presented a gist to use bash, ncal and Perl to create a week counting calendar on a terminal, I thought, hey this could be done in Perl alone.

cal v0.01.png

What's the point?

Here-in lies the problem with the irresponsible, belligerent coder, unsatisfied with mere re-implementation of another's code, who has to add his own flavours into the profusion of existing successful recipes. After all, MetaCPAN has no shortage of Calendar Modules, including Manwar's collection of excellent exotic calendars. EDIT: In fact Dave Cross' Calendar::Simple has an example which does exactly this.

I have started yet another project, this time a Calendar Application for the Terminal, which will (eventually) be interactive, customisable, use terminal colours for highlighting, allow adding and removing of events, will import, export and use standard .ics files, and create crontab lines. Or it might end up an exercise that once again reveals how inadequacies overcome aspirations.

Similar things exist (CalCurses, uses curses library) and (khal in Python) as well as cal and ncal, for those interested in such tools. Of course, I know my limitations, and this project will be Pure Perl. Pure Madness. Of course, if someone gets the title of this blog, somehow, it will prove to me that there are such other mad people around.

Data::Fake::CPAN (a PTS 2024 supplement)

rjbs forgot what he was saying

Published by Ricardo Signes on Sunday 12 May 2024 12:00

One of the things I wrote at the first PTS (back when it was called the Perl QA Hackathon) was Module::Faker. I wrote about it back then (way back in 2008), and again eleven years later. It’s a library that, given a description of a (pretend) CPAN distribution, produces that distribution as an actual file on disk with all the files the dist should have.

Every year or two I’ve made it a bit more useful as a testing tool, mostly for PAUSE. Here’s a pretty simple sample of how those tests use it:

$pause->upload_author_fake(PERSON => 'Not-Very-Meta-1.234.tar.gz', {
  omitted_files => [ qw( META.yml META.json ) ],
});

This writes out Not-Very-Meta-1.234.tar.gz with a Makefile.PL, a manifest, and other stuff. The package and version (and a magic true value) also appear in lib/Not/Very/Meta.pm. Normally, you’d also get metafiles, but here we’ve told Module::Faker to omit them, so we can test what happens without them. When we were talking about testing the new PAUSE server in Lisbon, we knew we’d have to upload distributions and see if they got indexed. Here, we wouldn’t want to just make the same test distribution over and over, but to quickly get new ones that wouldn’t conflict with the old ones.

This sounded like a job for Module::Faker and a random number generator, so I hot glued the two things together. Before I get into explaining what I did, I should note that this work wasn’t very important, and we really only barely used it, because we didn’t really need that much testing. On the other hand, it was fun. I had fun writing it and seeing what it would generate, and I have plans to have more fun with it. After a long day of carefully reviewing cron job logs, this work was a nice goofy thing to do before dinner.

Data::Fake::CPAN

Data::Fake is a really cool library written by David Golden. It’s really simple, but that simplicity makes it powerful. The ideas are like this:

  1. it’s useful to have a function that, when called, returns random data
  2. to configure that generator, it’s useful to have a function that returns the kind of function discussed in #1
  3. these kinds of functions are useful to compose

So, for example, here’s some sample code from the library’s documentation:

my $hero_generator = fake_hash(
    {
        name      => fake_name(),
        battlecry => fake_sentences(1),
        birthday  => fake_past_datetime("%Y-%m-%d"),
        friends   => fake_array( fake_int(2,4), fake_name() ),
        gender    => fake_pick(qw/Male Female Other/),
    }
);

Each of those fake... subroutine calls returns another subroutine. So, in the end you have $hero_generator as a code reference that, when called, will return a reference to a five-key hash. Each value in the hash will be the result of calling the generators given as values in the fake_hash call.

It takes a little while to get used to working with the code generators this way, but once you do, it comes very easy to snap together generators of random data structures. (When you’re done here, why not check out David Golden’s talk about using higher-order functions to create Data::Fake?) Helpfully, as you can see above, Data::Fake comes with generators for a bunch of data types.

What I did was write a Data::Fake plugin, Data::Fake::CPAN, that provides generators for version strings, package names, CPAN author identities, license types, prereq structures and, putting those all together, entire CPAN distributions. So, this code works:

use Data::Fake qw(CPAN);

my $dist = fake_cpan_distribution()->();

my $archive = $dist->make_archive({ dir => '.' });

When run, this writes out an archive file to disk. For example, I just got this:

$ ./nonsense/module-blaster
Produced archive as ./Variation-20010919.556.tar.gz (cpan author: MDUNN)
- Variation
- Variation::Colorless
- Variation::Conventional
- Variation::Dizzy

There are a few different kinds of date formats that it might pick. This time, it picked YYYYMMDD.xxx. That username, MDUNN, is short for Mayson Dunn. I found out by extracting the archive and reading the metadata. Here’s a sample of the prereqs:

{
  "prereqs" : {
    "build" : {
       "requires" : {
          "Impression::Studio" : "19721210.298"
       }
    },
    "runtime" : {
       "conflicts" : {
          "Writer::Cigarette" : "19830107.752"
       },
       "recommends" : {
          "Error::Membership" : "v5.16.17",
          "Marriage" : "v1.19.6"
       },
       "requires" : {
          "Alcohol" : "v12.16.0",
          "Competition::Economics" : "v19.1.7",
          "People" : "20100228.011",
          "Republic" : "20040805.896",
          "Transportation::Discussion" : "6.069"
       }
    }
  }
}

You’ll see that when I generated this, I ran ./nonsense/module-blaster. That program is in the Module-Faker repo, for your enjoyment. I hope to play with it more in the future, changing the magic true values, maybe adding real code, and just more variation — but probably centered around things that will have real impact on how PAUSE indexes things.

Probably very few people have much use for Module::Faker, let alone Data::Fake::CPAN. I get that! But Data::Fake is pretty great, and pretty useful for lots of testing. Also, generating fun, sort of plausible data makes testing more enjoyable. I don’t know why, but I always like watching my test suite fail more when it’s spitting out fun made-up names at the same time. Try it yourself!

(cdxcv) 8 great CPAN modules released last week

r/perl

Published by /u/niceperl on Sunday 12 May 2024 07:43

(cdxcv) 8 great CPAN modules released last week

Niceperl

Published by Unknown on Sunday 12 May 2024 09:43

Updates for great CPAN modules released last week. A module is considered great if its favorites count is greater or equal than 12.

  1. DBD::Oracle - Oracle database driver for the DBI module
    • Version: 1.90 on 2024-05-07, with 31 votes
    • Previous CPAN version: 1.83 was 2 years, 3 months, 21 days before
    • Author: ZARQUON
  2. Firefox::Marionette - Automate the Firefox browser with the Marionette protocol
    • Version: 1.57 on 2024-05-06, with 16 votes
    • Previous CPAN version: 0.77 was 4 years, 9 months, 30 days before
    • Author: DDICK
  3. Minion::Backend::mysql - MySQL backend
    • Version: 1.005 on 2024-05-06, with 13 votes
    • Previous CPAN version: 1.004 was 6 months, 6 days before
    • Author: PREACTION
  4. Path::Tiny - File path utility
    • Version: 0.146 on 2024-05-08, with 188 votes
    • Previous CPAN version: 0.144 was 1 year, 5 months, 7 days before
    • Author: DAGOLDEN
  5. PDL - Perl Data Language
    • Version: 2.089 on 2024-05-11, with 52 votes
    • Previous CPAN version: 2.088 was 20 days before
    • Author: ETJ
  6. Perl::Tidy - indent and reformat perl scripts
    • Version: 20240511 on 2024-05-10, with 140 votes
    • Previous CPAN version: 20240202 was 3 months, 9 days before
    • Author: SHANCOCK
  7. Prima - a Perl graphic toolkit
    • Version: 1.73 on 2024-05-09, with 43 votes
    • Previous CPAN version: 1.72 was 3 months, 9 days before
    • Author: KARASIK
  8. SPVM - The SPVM Language
    • Version: 0.990006 on 2024-05-09, with 31 votes
    • Previous CPAN version: 0.990003 was 8 days before
    • Author: KIMOTO

The magical number game

dev.to #perl

Published by Simon Green on Sunday 12 May 2024 06:19

Weekly Challenge 268

Each week Mohammad S. Anwar sends out The Weekly Challenge, a chance for all of us to come up with solutions to two weekly tasks. My solutions are written in Python first, and then converted to Perl. It's a great way for us all to practice some coding.

Challenge, My solutions

Task 1: Magic Number

Task

You are given two arrays of integers of same size, @x and @y.

Write a script to find the magic number that when added to each elements of one of the array gives the second array. Elements order is not important.

My solution

For input via the command line, I take a list of integers and then split the list in two. Calling the Python function directly takes two list.

For this task I numerically sort the two lists x and y. I then calculate the different between the first values in each list, and store this as diff.

I then loop through each position in the list to ensure the difference between the integers in that position in each list is diff. If it isn't, I exit early.

def magic_number(x: list, y: list) -> int | None:
    x = sorted(x)
    y = sorted(y)

    diff = y[0] - x[0]

    for i in range(len(x)):
        if y[i] - x[i] != diff:
            return None

    return diff

Examples

$ ./ch-1.py 3 7 5 9 5 7
2

$ ./ch-1.py 1 2 1 5 4 4
3

$ ./ch-1.py 2 5
3

Task 2: Number Game

Task

You are given an array of integers, @ints, with even number of elements.

Write a script to create a new array made up of elements of the given array. Pick the two smallest integers and add it to new array in decreasing order i.e. high to low. Keep doing until the given array is empty.

My solution

This is relatively straight forward, so doesn't need much explanation. For this task, I sort the list and then swap each pairs of numbers (1st and 2nd, 3rd and 4th, etc).

Both Python and Perl support the x, y = y, x syntax to swap numbers without using a temporary value.

def numbers_game(ints: list) -> list:
    ints = sorted(ints)

    for i in range(0, len(ints), 2):
        ints[i], ints[i+1], = ints[i+1], ints[i]

    return ints

Examples

$ ./ch-2.py 2 5 3 4
(3, 2, 5, 4)

$ ./ch-2.py 9 4 1 3 6 4 6 1
(1, 1, 4, 3, 6, 4, 9, 6)

$ ./ch-2.py 1 2 2 3
(2, 1, 3, 2)

German Perl/Raku Workshop 2024 recordings on YouTube

r/perl

Published by /u/Adriaaaaaaaan on Saturday 11 May 2024 11:27

Can someone explain this to me?

r/perl

Published by /u/UnicodeConfusion on Friday 10 May 2024 17:03

On this site: https://codegolf.stackexchange.com/questions/246845/convert-json-object-of-directories-to-list-of-paths

There is an interesting perl solution but I'm trying to wrap my head around it and am baffled.

map/}/?/{/&&say($s)..$s=~s|[^/]+/$||:($s.=s/"//gr."/"),/{?}|".+?"/g When I do a simple test: my $s = <some json string> .. the map above I don't get any output. Thanks in advance 
submitted by /u/UnicodeConfusion
[link] [comments]

Outreachy Internship 2024 Updates

Perl Foundation News

Published by Makoto Nozaki on Thursday 09 May 2024 19:21

TL;DR We just finished intern selection for this year’s Outreachy program. We got more projects and more applicants than the previous years, which made the selection hard in a good way.

Continuing our annual tradition, The Perl and Raku foundation is involved in the Outreachy program which provides internships to people subject to systemic bias and impacted by underrepresentation.

We have just finished the intern selection process, which turned out to be harder compared to the previous years. I’ll explain the reasons below.

It was harder because we got multiple high quality project proposals

Each year, we call for project ideas from the Perl/Raku community. Project proposer is required to commit to mentoring an intern from May to August. Given the significant commitment involved, it’s not uncommon for us to find suitable projects.

Fortunately, this year, we got two promising project proposals. The Foundation’s financial situation did not allow us to sponsor both projects, so we had to make the tough decision to support only one project.

After careful consideration, the Board has elected to sponsor Open Food Fact’s Perl project, titled “Extend Open Food Facts to enable food manufacturers to open data and improve food product quality.”

It was harder because more people showed up

Having more projects means we were able to attract more intern candidates. Across the two projects, more than 50 people showed interest and initiated contributions. Among them, 21 individuals actually created pull requests before the selection process.

Needless to say, it's hard work for the mentors to help dozens of candidates. They taught these intern candidates how to code and guided them through creating pull requests. On the applicants’ side, I am amazed that they worked hard to learn Perl and became proficient enough to create pull requests and make real improvements to the systems.

And the final selection was harder because we had more applicants

After the contribution process, we got an application from 14 people. It was obviously hard for the mentors to select one from so many good applicants. In the next post, Stéphane Gigandet will introduce our new intern to the community.

I wish all the best to the mentors, Stéphane and Alex, and our new intern.

Voice from the applicants

"In the journey to understand Perl better, I wanted to know what are its most wide applications, one of them being a web scraper. It's because Perl's strong support for regular expressions and built-in text manipulation functions make it well-suited for tasks like web scraping, where parsing and transforming text are essential. I took inspiration from various web scraping projects available on the internet to gain insights into the process and developed a lyrics scraper."

"I'm currently diving into Perl, and I see this as a fantastic chance to enrich my coding skills. I've thoroughly enjoyed immersing myself in it and have had the opportunity to explore various technologies like Docker and more."

"I have had the opportunity to experience Perl firsthand and have come to appreciate its significance in web development, on which I have worked. During my second year, I was searching for popular languages in backend development and found out about Perl, whose syntax was somewhat like C and Python. I didn't have any previous experience working with Perl, but now I have gained a deep understanding of its importance and impact on backend development and data processing."

"In this pull request, I made a significant stride in improving the quality and maintainability of our Perl codebase by integrating Perl::Critic, a powerful static code analysis tool."

"I've learned a whole lot about Perl and some of its frameworks such as Dancer2 (a surprisingly simple framework I've come to fall in love with)."

What's new on CPAN - April 2024

perl.com

Published on Thursday 09 May 2024 19:00

Welcome to “What’s new on CPAN”, a curated look at last month’s new CPAN uploads for your reading and programming pleasure. Enjoy!

APIs & Apps

Config & Devops

Data

Development & Version Control

Science & Mathematics

Web

Other

Fcntl: add module documentation

Perl commits on GitHub

Published by mauke on Thursday 09 May 2024 05:11

Fcntl: add module documentation

Maintaining Perl (Tony Cook) February 2024

Perl Foundation News

Published by alh on Monday 06 May 2024 19:42


Tony writes:

``` [Hours] [Activity] 2024/02/01 Thursday

2.50 #21873 fix, testing on both gcc and MSVC, push for CI

2.50

2024/02/02 Friday 0.72 #21915 review, testing, comments

0.25 #21883 review recent updates, apply to blead

0.97

2024/02/05 Monday 0.25 github notifications 0.08 #21885 review updates and approve 0.57 #21920 review and comment 0.08 #21921 review and approve 0.12 #21923 review and approve 0.08 #21924 review and approve 0.08 #21926 review and approve 0.67 #21925 review and comments

2.00 #21877 code review, testing

3.93

2024/02/06 Tuesday 0.23 #21925 comment 0.52 review coverity scan report, reply to email from jkeenan 0.27 #21927 review and comment 0.08 #21928 review and approve

0.08 #21922 review and approve

1.18

2024/02/07 Wednesday 0.25 github notifications 0.52 #21935 review, existing comments need addressing

2.12 #21877 work on fix, push for CI most of a fix

2.89

2024/02/08 Thursday 0.40 #21927 review and approve 0.23 #21935 review, check each comment has been addressed, approve 0.45 #21937 review and approve 0.15 #21938 review and comment 0.10 #21939 review and approve 0.13 #21941 review and approve 0.10 #21942 review and approve 0.08 #21943 review and approve 0.07 #21945 review and approve 0.17 #21877 look into CI failures, think I found problem, push probable fix 0.18 #21927 make a change to improve pad_add_name_pvn() docs, testing, push for CI 2.20 #21877 performance test on cygwin, try to work up a

regression test

4.26

2024/02/12 Monday 0.60 #18606 fix minor issue pointed out by mauke, testing 0.40 github notifications 0.08 #21872 review latest changes and approve 0.08 #21920 review latest changes and approve 1.48 #21877 debugging test 0.30 #21524 comment on downstream ticket

0.27 #21724 update title to match reality and comment

3.21

2024/02/13 Tuesday 0.35 #21915 review, brief comment 0.25 #21983 review and approve 0.03 #21233 close 0.28 #21878 comment 0.08 #21927 check CI results and make PR 21984 0.63 #21877 debug failing CI 0.27 #21984 follow-up 0.58 #21982 review, testing, comments

0.32 #21979 review and approve

2.79

2024/02/14 Wednesday 1.83 #21958 testing, finally reproduce, debugging and comment 0.08 #21987 review discussion and briefly comment 0.08 #21984 apply to blead 0.22 #21977 review and approve 0.12 #21988 review and approve 0.15 #21990 review and approve 0.82 #21550 probable fix, build tests 0.38 coverity scan follow-up 1.27 #21829/#21558 (related to 21550) debugging

0.65 #21829/#21558 more debugging, testing, comment

5.60

2024/02/15 Thursday 0.15 github notifications 0.08 #21915 review updates and approve 2.17 #21958 debugging, research, long comment 0.58 #21958 testing, follow-up

0.12 #21991 review and approve

3.10

2024/02/19 Monday 0.88 #21161 review comment and reply, minor change, testing, force push 0.23 #22001 review and comment 0.30 #22002 review and comment 0.12 #22004 review and comment 0.28 #22005 review and approve 0.32 #21993 testing, review changes 1.95 #21661 review comments on PR and fixes, review code and

history for possible refactor of vFAIL*() macros

4.08

2024/02/20 Tuesday 0.35 github notifications 0.08 #22010 review and approve 0.08 #22007 review and approve with comment 0.60 #22006 review, research and approve with comment 0.08 #21989 review and approve 0.58 #21996 review, testing, comment 0.22 #22009 review and approve 0.50 #21925 review latest updates and approve

1.05 #18606 apply to blead, work on a perldelta, make PR 22011

3.54

2024/02/21 Wednesday 0.18 #22011 fixes 0.80 #21683 refactoring

1.80 #21683 more refactor

2.78

2024/02/22 Thursday 0.38 #22007 review and comment 0.70 #21161 apply to blead, perldelta as PR22017 1.75 smoke report checks: testing win32 gcc failures 0.27 #22007 review updates and approve

1.15 #21661 re-check, research and push for smoke/ci

4.25

2024/02/26 Monday 2.10 look over smoke reports, debug PERLIO=stdio failure on mac

1.38 more debug PERLIO=stdio

3.48

2024/02/27 Tuesday 0.08 #22029 review and apply to blead 0.27 #22024 review and approve 0.33 #22026 review and approve 0.08 #22027 review and approve 0.10 #22028 review and approve 0.08 #22030 review and comment, conditionally approve 0.25 #22033 review, comments and approve 0.08 #22034 review and approve 0.17 #22035 review and comment

0.78 #21877 debugging

2.22

2024/02/28 Wednesday 0.38 github notifications 0.52 #22040 review discussion, research and comment 0.13 #22043 review and approve 0.12 #22044 review and approve 0.72 #22045 review, research, comment and approve 0.13 #22046 review, research and approve

1.55 #21877 more debugging (unexpected leak)

3.55

2024/02/29 Thursday 0.15 #21966 review update and approve 1.18 #21877 debugging

0.13 fix $DynaLoader::VERSION

1.46

Which I calculate is 55.79 hours.

Approximately 70 tickets were reviewed or worked on, and 5 patches were applied. ```

Announcing The London Perl & Raku Workshop 2024

dev.to #perl

Published by Lee J on Monday 06 May 2024 14:39

The London Perl & Raku Workshop (LPW) will take place this year on Saturday 26th October and you are encouraged to submit your talk proposals now. The venue is in final stages of being confirmed - it will be in central London (UK).

We'd also like to announce our CFP. We welcome proposals relating to Perl 5, Raku, other languages, and supporting technologies. We may even have space for a couple of talks entirely tangential as we are close to finalising the venue (very central London) and should have room for two tracks.

Talks may be long (40mins), short (20 mins), or very short (aka lightning, 5 mins) but we would prefer talks to be on the shorter side and will likely prioritise 20min talks. We would also be pleased to accept proposals for tutorials and discussions. The deadline for submissions is 30th September.

We would really like to have more first time speakers. If you’d like help with a talk proposal, and/or the talk itself, let us know - we’ve got people happy to be your talk buddy!

Register (it's free!) and submit your talk on the workshop site.

We would also like to make a call for sponsors - does your company want to support the workshop? By sponsoring LPW you can demonstrate your support for the Perl and/or Raku languages and nurture your relationship with the local developer community. Much more information can be found on the workshop site along with a sponsor prospectus.

As well as the benefits as listed on the aforementioned page, sponsors will all feature in blog posts, news posts, social media posts.

That starts right now, with our first sponsors who have already generously sponsored the workshop:

With thanks from The London Perl & Raku Workshop 2024 organising team.

POSIX/t/wrappers.t: One-character typo

Perl commits on GitHub

Published by jkeenan on Sunday 05 May 2024 21:22

POSIX/t/wrappers.t: One-character typo

(cdxciv) 17 great CPAN modules released last week

Niceperl

Published by Unknown on Saturday 04 May 2024 22:46

Updates for great CPAN modules released last week. A module is considered great if its favorites count is greater or equal than 12.

  1. App::cpm - a fast CPAN module installer
    • Version: 0.997017 on 2024-04-28, with 72 votes
    • Previous CPAN version: 0.997015 was 3 months, 24 days before
    • Author: SKAJI
  2. App::DBBrowser - Browse SQLite/MySQL/PostgreSQL databases and their tables interactively.
    • Version: 2.410 on 2024-05-04, with 14 votes
    • Previous CPAN version: 2.407 was 1 month, 24 days before
    • Author: KUERBIS
  3. App::Netdisco - An open source web-based network management tool.
    • Version: 2.076004 on 2024-05-03, with 16 votes
    • Previous CPAN version: 2.076001 was 9 days before
    • Author: OLIVER
  4. CPAN::Audit - Audit CPAN distributions for known vulnerabilities
    • Version: 20240503.001 on 2024-05-03, with 13 votes
    • Previous CPAN version: 20240414.001 was 18 days before
    • Author: BDFOY
  5. CPAN::Changes - Parser for CPAN style change logs
    • Version: 0.500004 on 2024-05-02, with 32 votes
    • Previous CPAN version: 0.500003 was 2 months, 9 days before
    • Author: HAARG
  6. DBD::mysql - A MySQL driver for the Perl5 Database Interface (DBI)
    • Version: 5.005 on 2024-05-01, with 55 votes
    • Previous CPAN version: 5.004 was 1 month, 13 days before
    • Author: DVEEDEN
  7. DBIx::DataModel - UML-based Object-Relational Mapping (ORM) framework
    • Version: 3.11 on 2024-04-28, with 12 votes
    • Previous CPAN version: 3.10 was 1 month, 17 days before
    • Author: DAMI
  8. Devel::CheckOS - a script to package Devel::AssertOS modules with your code.
    • Version: 2.01 on 2024-05-02, with 17 votes
    • Previous CPAN version: 1.96 was 1 year, 2 months, 26 days before
    • Author: DCANTRELL
  9. Email::MIME - easy MIME message handling
    • Version: 1.954 on 2024-05-02, with 20 votes
    • Previous CPAN version: 1.953 was 1 year, 3 months, 24 days before
    • Author: RJBS
  10. GD - Perl interface to the libgd graphics library
    • Version: 2.81 on 2024-05-03, with 28 votes
    • Previous CPAN version: 2.78 was 9 months, 30 days before
    • Author: RURBAN
  11. Module::Build::Tiny - A tiny replacement for Module::Build
    • Version: 0.048 on 2024-04-28, with 16 votes
    • Previous CPAN version: 0.047 was 7 months before
    • Author: LEONT
  12. Net::DNS - Perl Interface to the Domain Name System
    • Version: 1.45 on 2024-05-02, with 26 votes
    • Previous CPAN version: 1.44 was 2 months, 16 days before
    • Author: NLNETLABS
  13. PerlPowerTools - BSD utilities written in pure Perl
    • Version: 1.045 on 2024-04-30, with 39 votes
    • Previous CPAN version: 1.044 was 1 month, 27 days before
    • Author: BRIANDFOY
  14. SPVM - The SPVM Language
    • Version: 0.990003 on 2024-05-01, with 31 votes
    • Previous CPAN version: 0.990001 was 5 days before
    • Author: KIMOTO
  15. Syntax::Keyword::Match - a match/case syntax for perl
    • Version: 0.14 on 2024-04-30, with 12 votes
    • Previous CPAN version: 0.13 was 9 months, 10 days before
    • Author: PEVANS
  16. Term::Choose - Choose items from a list interactively.
    • Version: 1.765 on 2024-05-02, with 15 votes
    • Previous CPAN version: 1.764 was 12 days before
    • Author: KUERBIS
  17. version - Structured version objects
    • Version: 0.9932 on 2024-04-28, with 21 votes
    • Previous CPAN version: 0.9931 was 1 day before
    • Author: LEONT

TPRF sponsors Perl Toolchain Summit

Perl Foundation News

Published by Makoto Nozaki on Friday 03 May 2024 19:49

I am pleased to announce that The Perl and Raku Foundation sponsored the Perl Toolchain Summit 2024 as a Platinum Sponsor.

The Perl Toolchain Summit (PTS) is an annual event where they bring together the volunteers who work on the tools and modules at the heart of Perl and the CPAN ecosystem. The PTS gives them 4 days to work together on these systems, with all their fellow volunteers to hand.

The event successfully concluded in Lisbon, Portugal at the end of April 2024.

If you or your company is willing to help the future PTS events, you can get in touch with the PTS team. Alternatively, you can make a donation to The Perl and Raku Foundation, which is a 501(c)(3) organization.

PTS 2024: Lisbon

rjbs forgot what he was saying

Published by Ricardo Signes on Friday 03 May 2024 15:19

Almost exactly a year since the last Perl Toolchain Summit, it was time for the next one, this time in Lisbon. Last year, I wrote:

In 2019, I wasn’t sure whether I would go. This time, I was sure that I would. It had been too long since I saw everyone, and there were some useful discussions to be had. I think that overall the summit was a success, and I’m happy with the outcomes. We left with a few loose threads, but I’m feeling hopeful that they can, mostly, get tied up.

Months later, I did not feel hopeful. They were left dangling, and I felt like some of the best work I did was not getting any value. I was grouchy about it, and figured I was done. Then, though, I started thinking that there was one last project I’d like doing for PAUSE: Upgrading the server. It’s the thing I said I wanted to do last year, but barely even started. This year, I said that if we could get buy-in to do it, I’d go. Since I’m writing this blog post, you know I went, and I’m going to tell you about it.

PAUSE Bootstrap

Last year, Matthew and I wanted to make it possible to quickly spin up a working PAUSE environment, so we could replace the long-suffering “pause2” server. We were excited by the idea of starting from work that Kenichi Ishigaki had done to create a Docker container running a test instance. We only ended up doing a little work on that, partly because we thought we’d be starting from scratch and didn’t know enough Docker to be useful.

This year, we decided it’d be our whole mission. We also said that we were not going to start with Docker. Docker made sense, it was probably a great way to do it, but Matthew and I still aren’t Docker users. We wanted results, and we felt the way to get them was to stick to what we know: automated installation and configuration of an actual VM. We pitched this plan to Robert Spier, one of the operators of the Perl NOC and he was on board. I leaned on him pretty hard to actually come to Lisbon and help, and he agreed. (He also said that a sufficiently straightforward installer would be a good starting point for turning things into Docker containers later, which was reassuring.)

At Fastmail, where Matthew and I work, we can take every other Friday for experimental or out-of-band work, and we decided we’d get started early. If the installer was done by the time we arrived, we’d be in a great position to actually ship. This was a great choice. Matthew and I, with help from another Fastmail colleague, Marcus, wrote a program. It started off life as unpause, but is now in the repo as bootstrap/mkpause. You can read the PAUSE Bootstrap README if you want to skip to “how do I use this?”.

The idea is that there’s a program to run on a fresh Debian 12 box. That installs all the needed apt packages, configures services, sets up Let’s Encrypt, creates unix users, builds a new perl, installs systemd services, and gets everything running. There’s another program that can create that fresh Debian 12 box for you, using the DigitalOcean API. (PAUSE doesn’t run in DigitalOcean, but Fastmail has an account that made it easy to use for development.)

I think Matthew and I worked well together on this. We found different rabbit holes interesting. He fixed hard problems I was (barely) content to suffer with. (There was some interesting nonsense with the state of apt locking and journald behavior shortly after VM “cloud init”.) I slogged through testing exactly whether each cron job ran correctly and got a pre-built perl environment ready for quick download, to avoid running plenv and cpanm during install.

Before we even arrived, we could go from zero to a fully running private PAUSE server in about two and a half minutes! Quick builds meant we could iterate much faster. We also had a script to import all of PAUSE’s data from the live PAUSE. It took about ten minutes to run, but we had it down to one minute by day two.

When we arrived, I took my todo and threw it up on the wall in the form of a sticky note kanban board.

PTS Stickies: Day 1

We spent day one re-testing cron jobs, improving import speed, and (especially) asking Andreas König all kinds of questions about things we’d skipped out of confusion. More on those below, but without Andreas, we could easily have broken or ignored critical bits of the system.

By the end of day two, we were confident that we could deploy the next day. I’d hoped we could deploy on day two, but there were just too many bits that were not quite ready. Robert had spent a bunch of time running the installer on the VM where he intended to run the new production PAUSE service, known at the event as “pause3”. There were networking things to tweak, and especially storage volume management. This required the rejiggering of a bunch of paths, exposing fun bugs or incorrect assumptions.

The first thing we did on day three was start reviewing our list of pre-deploy acceptance tests. Did everything on the list work? We thought so. We took down pause2 for maintenance at 10:00, resynchronized everything, watched a lot of logs, and did some uploads. We got some other attendees to upload things to pause3. Everything looked good, so we cut pause.perl.org over to pause3. It worked! We were done! Sort of.

We had some more snags to work through, but it was just the usual nonsense. A service was logging to the wrong place. The new MySQL was stricter about data validation than the old one. An accidental button-push took down networking on the VM. Everything got worked out in the end. I’ll include some “weird stuff that happened” below, but the short version is: it went really smoothly, for this kind of work.

On day four, we got to work on fit and finish. We cleaned up logging noise, we applied some small merge requests that we’d piled up while trying to ship. We improved the installer to move more configuration into files, instead of being inlined in the installer. Also, we prepared pull requests to delete about 20,000 lines of totally unused files. This is huge. When trying to learn how an older codebase works, it can be really useful to just grep the code for likely variable names or known subroutines. When tens of thousands of lines in the code base are unused, part of the job becomes separating live code out from dead code, instead of solving a problem.

We also overhauled a lot of documentation. It was exciting to replace the long and bit-rotted “how to install a private PAUSE” with something that basically said “run this program”. It doesn’t just say that, though, and now it’s accurate and written from the last successful execution of the process. You can read how to install PAUSE yourself.

Matthew, Robert, and I celebrated a successful PTS by heading off to Belém Tower to see the sights and eat pastéis.

I should make clear, finally, that the PAUSE team was five people. Andreas König and Kenichi Ishigaki were largely working on other goals not listed here. It was great to have them there for help on our work, but they got other things done, not documented in this post!

Here’s our kanban board from the end of day four:

PTS Stickies: Day 4

Specifics of Note

run_mirrors.sh

This was one of the two mirroring-related scripts we had to look into. It was bananas. Turns out that PAUSE had a list of users who ran their own FTP servers. It would, four times a day, connect to those servers and retrieve files from them directly into the users’ home directories on PAUSE.

Beyond the general bananas-ness of this, the underlying non-PAUSE program in /usr/bin/mirror no longer runs, as it uses $*, eliminated back in v5.30. Rather than fix it and keep something barely used and super weird around, we eliminated this feature. (I say “barely used”, but I found no evidence it was used at all.)

make-mirror-yaml.pl

The other mirror program! This one updated the YAML file that exposes the CPAN mirror list. Years ago, the mirror list was eliminated, and a single name now points to a CDN. Still, we were diligently updating the mirror list every hour. No longer.

rrrsync

You can rsync from CPAN, but it’s even better to use rrr. With rrr, the PAUSE server is meant to maintain a few lists of “files that changed in a given time window”. Other machines can then synchronize only files that have changed since they last checked, with occasionally full-scan reindexes.

We got this working pretty quickly, but it seemed to break at the last minute. What had happened? We couldn’t tell, everything looked great, and there were no errors. Eventually, I found myself using strace against perl. It turned out that during our reorganization of the filesystem, we’d moved where the locks live. We put in a symlink for the old name, and that’s what rrr was using… but it didn’t follow symlinks when locking. Once we updated the configuration to use the canonical name and not the link, everything worked.

Matthew said, “You solved a problem with strace!” I said, “I know!” Then we high fived and got back to work.

I was never happy with the symlinks we introduced during the filesystem reorganization, but I was happy when I eliminated the last one during day four cleanup!

the root partition filled up

We did all this work to keep the data partition capable of growth, and then / filled up. Ugh.

It turned out it was logs. This wasn’t too much of a surprise, but it was annoying. It was especially annoying because we decided early on that we’d just accept using journald for all our logging, and that should’ve kept us from going over quota.

It turned out that on the VM, something had installed a service I’d never heard of. Its job was to notice when something wanted to use the named syslog socket, and then start rsyslogd. Once that happened, we were double-logging a ton of stuff, and there was no log rotation configured. We killed it off.

We did other tuning to make sure we’d keep enough logs without running out of space, but this was the interesting part.

Future Plans

We have some. If nothing else, I’m dying to see my pull request 405 merged. (It’s the thing I wrote last year.) I have a bunch of half-done work that will be easier to finish after that. But the problem was: would this wait another year?

We finished our day — just before heading off to Belém — by talking about development between now and then. I said, “Look, I feel really demotivated and uninterested if I can’t continuously ship and review real improvements.” Andreas said, “I don’t want to see things change out from under me without understanding what happened.”

The five of us agreed to create a private PAUSE operations mailing list where we’d announce (or propose) changes and problems. We all joined, along with Neil Bowers, who is an important part of the PAUSE team but couldn’t attend Lisbon. With that, we felt good about keeping improvements flowing through the year. Robert has been shipping fixes to log noise. I’ve got a significant improvement to email handling in the wings. It’s looking like an exciting year ahead for PAUSE! (That said, it’s still PAUSE. Don’t expect miracles, okay?)

Thanks to our sponsors and organizers

The Perl Toolchain Summit is one of the most important events in the year for Perl. A lot of key projects have folks get together to get things done. Some of them are working all year, and use this time for deep dives or big lifts. Others (like PAUSE) are often pretty quiet throughout the year, and use this time to do everything they need to do for the year.

Those of us doing stuff need a place to work, and we need to a way to get there and sleep, and we’re also pretty keen on having a nice meal or two together. Our sponsors and organizers make that possible. Our sponsors provide much-needed money to the organizers, and the organizers turn that money into concrete things like “meeting rooms” and “plane tickets”.

I offer my sincere thanks to our organizers: Laurent Boivin, Philippe Bruhat, and Breno de Oliveira, and also to our sponsors. This year, the organizers have divided sponsors into those who handed over cash and those who provided in-kind donation, like people’s time or paying attendee’s airfare and hotel bills directly. All these organizations and people are helping to keep Perl’s toolchain operational and improving. Here’s the breakdown:

Monetary sponsors: Booking.com, The Perl and Raku Foundation, Deriv, cPanel, Inc Japan Perl Association, Perl-Services, Simplelists Ltd, Ctrl O Ltd, Findus Internet-OPAC, Harald Joerg, Steven Schubiger.

In kind sponsors: Fastmail, Grant Street Group, Deft, Procura, Healex GmbH, SUSE, Zoopla.

Breno especially should get called out for organizing this from five thousand miles away. You never could’ve guessed, and it ran exceptionally smoothly. Also, it meant I got to see Lisbon, which was a terrific city that I probably would not have visited any time soon otherwise. Thanks, Breno!

List of new CPAN distributions – Apr 2024

Perlancar

Published by perlancar on Wednesday 01 May 2024 02:38

dist author abstract date
AI-Ollama-Client CORION Client for AI::Ollama 2024-04-05T09:15:33
Acme-CPANModules-BPOM-FoodRegistration PERLANCAR List of modules and utilities related to Food Registration at BPOM 2024-04-27T00:06:16
Acme-CPANModules-JSONVariants PERLANCAR List of JSON variants/extensions 2024-04-29T00:05:46
Alien-NLOpt DJERIUS Build and Install the NLOpt library 2024-04-28T00:59:11
Alien-onnxruntime EGOR Discover or download and install onnxruntime (ONNX Runtime is a cross-platform inference and training machine-learning accelerator.) 2024-04-17T22:03:45
AnyEvent-I3X-Workspace-OnDemand WATERKIP An I3 workspace loader 2024-04-12T18:33:21
App-papersway SPWHITTON PaperWM-like window management for Sway/i3wm 2024-04-12T08:18:00
App-sort_by_comparer PERLANCAR Sort lines of text by a Comparer module 2024-04-16T00:06:00
App-sort_by_example PERLANCAR Sort lines of text by example 2024-04-20T00:05:10
App-sort_by_sorter PERLANCAR Sort lines of text by a Sorter module 2024-04-17T00:05:42
App-sort_by_sortkey PERLANCAR Sort lines of text by a SortKey module 2024-04-24T00:06:38
Arithmetic-PaperAndPencil JFORGET simulating paper and pencil techniques for basic arithmetic operations 2024-04-22T19:57:44
Bencher-Scenario-ExceptionHandling PERLANCAR Benchmark various ways to do exception handling in Perl 2024-04-13T00:05:36
CPAN-Requirements-Dynamic LEONT Dynamic prerequisites in meta files 2024-04-27T15:17:57
CSAF GDT Common Security Advisory Framework 2024-04-23T21:49:42
CXC-DB-DDL DJERIUS DDL for table creation, based on SQL::Translator::Schema 2024-04-04T16:24:13
Captcha-Stateless-Text HIGHTOWE stateless, text-based CAPTCHAs 2024-04-17T21:19:21
Carp-Object DAMI a replacement for Carp or Carp::Clan, object-oriented 2024-04-28T17:58:22
Carp-Patch-OutputToBrowser PERLANCAR Output stacktrace to browser as HTML instead of returning it 2024-04-25T00:05:19
Catalyst-Plugin-Flash ARISTOTLE put values on the stash of the next request 2024-04-09T05:06:19
Comparer-date_in_text PERLANCAR Compare date found in text (or text asciibetically, if no date is found) 2024-04-18T00:05:43
Crypt-Passphrase-Bcrypt-Compat LEONT A bcrypt encoder for Crypt::Passphrase 2024-04-08T14:24:10
DBD-Mock-Session-GenerateFixtures UXYZAB When a real DBI database handle ($dbh) is provided, the module generates DBD::Mock::Session data. Otherwise, it returns a DBD::Mock::Session object populated with generated data. This not a part form DBD::Mock::Session distribution just a wrapper around it. 2024-04-29T18:25:02
Data-Dumper-UnDumper BIGPRESH load Data::Dumper output, including self-references 2024-04-25T21:42:30
Data-MiniDumpX PERLANCAR A simplistic data structure dumper (demo for Plugin::System) 2024-04-14T00:06:13
DateTime-Format-PDF SKIM PDF DateTime Parser and Formatter. 2024-04-01T09:23:07
Devel-Confess-Patch-UseDataDumpHTMLCollapsible PERLANCAR Use Data::Dump::HTML::Collapsible to stringify reference 2024-04-26T00:05:16
Devel-Confess-Patch-UseDataDumpHTMLPopUp PERLANCAR Use Data::Dump::HTML::PopUp to stringify reference 2024-04-28T00:06:05
Dist-Build LEONT A modern module builder, author tools not included! 2024-04-26T10:50:10
Dist-Zilla-Plugin-DistBuild LEONT Build a Build.PL that uses Dist::Build 2024-04-26T10:55:35
Dist-Zilla-Plugin-DynamicPrereqs-Meta LEONT Add dynamic prereqs to to the metadata in our Dist::Zilla build 2024-04-27T15:50:03
ExtUtils-Builder LEONT An overview of the foundations of the ExtUtils::Builder Plan framework 2024-04-25T12:14:45
ExtUtils-Builder-Compiler LEONT Portable compilation 2024-04-25T13:18:11
JSON-Ordered-Conditional LNATION A conditional language within an ordered JSON struct 2024-04-06T06:47:37
JSON-ToHTML ARISTOTLE render JSON-based Perl datastructures as HTML tables 2024-04-09T04:28:11
Knowledge RSPIER a great new dist 2024-04-27T11:13:53
Log-Any-Simple MATHIAS A very thin wrapper around Log::Any, using a functional interface that dies automatically when you log above a given level. 2024-04-24T19:51:03
Mo-utils-Country SKIM Mo country utilities. 2024-04-11T13:41:33
Mo-utils-Time SKIM Mo time utilities. 2024-04-12T14:28:06
Mo-utils-TimeZone SKIM Mo timezone utilities. 2024-04-03T16:34:52
Mojolicious-Plugin-Authentication-OIDC TYRRMINAL OpenID Connect implementation integrated into Mojolicious 2024-04-25T19:27:09
Mojolicious-Plugin-Cron-Scheduler TYRRMINAL Mojolicious Plugin that wraps Mojolicious::Plugin::Cron for job configurability 2024-04-16T11:48:54
Mojolicious-Plugin-Migration-Sqitch TYRRMINAL Run Sqitch database migrations from a Mojo app 2024-04-30T15:37:52
Mojolicious-Plugin-Module-Loader TYRRMINAL Automatically load mojolicious namespaces 2024-04-19T14:09:36
Mojolicious-Plugin-ORM-DBIx TYRRMINAL Easily load and access DBIx::Class functionality in Mojolicious apps 2024-04-03T13:32:06
Mojolicious-Plugin-SendEmail TYRRMINAL Easily send emails from Mojolicious applications 2024-04-01T20:40:24
Mojolicious-Plugin-Sessionless TYRRMINAL Installs noop handlers to disable Mojolicious sessions 2024-04-16T12:45:37
MooX-Pack LNATION The great new MooX::Pack! 2024-04-20T01:52:17
Net-Async-OpenExchRates VNEALV Interaction with OpenExchangeRates API 2024-04-20T11:46:28
Net-EPP-Server GBROWN A simple EPP server implementation. 2024-04-08T09:38:21
Number-Iterator LNATION The great new Number::Iterator! 2024-04-18T19:45:31
Parallel-TaskExecutor MATHIAS Cross-platform executor for parallel tasks executed in forked processes 2024-04-13T20:02:27
Plack-App-Login-Request SKIM Plack application for request of login information. 2024-04-29T14:23:02
Sah-SchemaBundle-Business-ID-BCA PERLANCAR Sah schemas related to BCA (Bank Central Asia) bank 2024-04-23T00:05:53
Sah-SchemaBundle-Business-ID-Mandiri PERLANCAR Sah schemas related to Mandiri bank 2024-04-30T00:05:43
Sah-SchemaBundle-Comparer PERLANCAR Sah schemas related to Comparer 2024-04-21T00:05:30
Sah-SchemaBundle-Path PERLANCAR Schemas related to filesystem path 2024-04-01T00:06:15
Sah-SchemaBundle-Perl PERLANCAR Sah schemas related to Perl 2024-04-02T00:05:40
Sah-SchemaBundle-SortKey PERLANCAR Sah schemas related to SortKey 2024-04-22T00:06:02
Sah-SchemaBundle-Sorter PERLANCAR Sah schemas related to Sorter 2024-04-03T00:14:57
Sah-Schemas-Sorter PERLANCAR Sah schemas related to Sorter 2024-04-03T00:05:43
Seven LNATION The great new Seven! 2024-04-13T03:30:11
Sort-Key-SortKey PERLANCAR Thin wrapper for Sort::Key to easily use SortKey::* 2024-04-04T00:05:05
SortExample-Color-Rainbow-EN PERLANCAR Ordered list of names of colors in the rainbow, in English 2024-04-05T00:06:12
SortKey-Num-pattern_count PERLANCAR Number of occurrences of string/regexp pattern as sort key 2024-04-06T00:05:41
SortKey-Num-similarity PERLANCAR Similarity to a reference string as sort key 2024-04-08T00:05:21
SortKey-date_in_text PERLANCAR Date found in text as sort key 2024-04-19T00:05:23
SortSpec PERLANCAR Specification of sort specification 2024-04-09T00:05:37
SortSpec-Perl-CPAN-ChangesGroup-PERLANCAR PERLANCAR Specification to sort changes group heading PERLANCAR-style 2024-04-10T00:05:24
Sorter-from_comparer PERLANCAR Sort by comparer generated by a Comparer:: module 2024-04-11T00:05:17
Sorter-from_sortkey PERLANCAR Sort by keys generated by a SortKey:: module 2024-04-12T00:05:58
Sqids MYSOCIETY generate short unique identifiers from numbers 2024-04-06T10:43:27
TableData-Business-ID-BPOM-FoodAdditive PERLANCAR Food additives in BPOM 2024-04-10T11:10:00
Tags-HTML-Image SKIM Tags helper class for image presentation. 2024-04-20T13:32:39
Tags-HTML-Login-Request SKIM Tags helper for login request. 2024-04-29T11:23:37
Test2-Tools-MIDI JMATES test MIDI file contents 2024-04-09T23:42:34
Tiny-Prof TIMKA Perl profiling made simple to use. 2024-04-26T07:19:38
Web-Async TEAM Future-based web+HTTP handling 2024-04-23T16:50:24
YAML-Ordered-Conditional LNATION A conditional language within an ordered YAML struct 2024-04-06T06:05:51
kraken PHILIPPE api.kraken.com connector 2024-04-05T09:11:35
papersway SPWHITTON PaperWM-like window management for Sway/i3wm 2024-04-12T07:52:39

Stats

Number of new CPAN distributions this period: 81

Number of authors releasing new CPAN distributions this period: 26

Authors by number of new CPAN distributions this period:

No Author Distributions
1 PERLANCAR 30
2 TYRRMINAL 7
3 LEONT 7
4 SKIM 7
5 LNATION 5
6 MATHIAS 2
7 SPWHITTON 2
8 DJERIUS 2
9 ARISTOTLE 2
10 PHILIPPE 1
11 JFORGET 1
12 VNEALV 1
13 RSPIER 1
14 UXYZAB 1
15 WATERKIP 1
16 GBROWN 1
17 CORION 1
18 EGOR 1
19 TIMKA 1
20 TEAM 1
21 BIGPRESH 1
22 HIGHTOWE 1
23 DAMI 1
24 MYSOCIETY 1
25 JMATES 1
26 GDT 1

What's new on CPAN - March 2024

perl.com

Published on Tuesday 30 April 2024 21:00

Welcome to “What’s new on CPAN”, a curated look at last month’s new CPAN uploads for your reading and programming pleasure. Enjoy!

APIs & Apps

Data

Development & Version Control

Science & Mathematics

Web

(cdxciii) 15 great CPAN modules released last week

Niceperl

Published by Unknown on Sunday 28 April 2024 09:07

Updates for great CPAN modules released last week. A module is considered great if its favorites count is greater or equal than 12.

  1. App::Netdisco - An open source web-based network management tool.
    • Version: 2.076001 on 2024-04-24, with 16 votes
    • Previous CPAN version: 2.075003 was 12 days before
    • Author: OLIVER
  2. Devel::Cover - Code coverage metrics for Perl
    • Version: 1.42 on 2024-04-26, with 101 votes
    • Previous CPAN version: 1.40 was 11 months, 26 days before
    • Author: PJCJ
  3. Devel::Size - Perl extension for finding the memory usage of Perl variables
    • Version: 0.84 on 2024-04-25, with 21 votes
    • Previous CPAN version: 0.83 was 5 years, 2 days before
    • Author: NWCLARK
  4. experimental - Experimental features made easy
    • Version: 0.032 on 2024-04-25, with 32 votes
    • Previous CPAN version: 0.031 was 1 year, 2 months, 25 days before
    • Author: LEONT
  5. HTML5::DOM - Super fast html5 DOM library with css selectors (based on Modest/MyHTML)
    • Version: 1.26 on 2024-04-25, with 12 votes
    • Previous CPAN version: 1.25 was 2 years, 9 months, 19 days before
    • Author: ZHUMARIN
  6. Compress::Zlib - IO Interface to compressed data files/buffers
    • Version: 2.212 on 2024-04-27, with 16 votes
    • Previous CPAN version: 2.211 was 21 days before
    • Author: PMQS
  7. JSON::Path - search nested hashref/arrayref structures using JSONPath
    • Version: 1.0.6 on 2024-04-26, with 12 votes
    • Previous CPAN version: 1.0.4 was 4 months, 15 days before
    • Author: POPEFELIX
  8. MIME::Body - Tools to manipulate MIME messages
    • Version: 5.515 on 2024-04-24, with 13 votes
    • Previous CPAN version: 5.514 was 2 months, 18 days before
    • Author: DSKOLL
  9. Module::CoreList - what modules shipped with versions of perl
    • Version: 5.20240420 on 2024-04-27, with 43 votes
    • Previous CPAN version: 5.20240320 was 1 month, 7 days before
    • Author: BINGOS
  10. PDL - Perl Data Language
    • Version: 2.088 on 2024-04-21, with 52 votes
    • Previous CPAN version: 2.019 was 5 years, 11 months, 16 days before
    • Author: ETJ
  11. SPVM - The SPVM Language
    • Version: 0.990001 on 2024-04-26, with 31 votes
    • Previous CPAN version: 0.989104 was 6 days before
    • Author: KIMOTO
  12. Test::MockModule - Override subroutines in a module for unit testing
    • Version: v0.178.0 on 2024-04-26, with 17 votes
    • Previous CPAN version: v0.177.0 was 2 years, 7 months, 19 days before
    • Author: GFRANKS
  13. Test::Simple - Basic utilities for writing tests.
    • Version: 1.302199 on 2024-04-25, with 190 votes
    • Previous CPAN version: 1.302198 was 4 months, 25 days before
    • Author: EXODIST
  14. Test2::Suite - Distribution with a rich set of tools built upon the Test2 framework.
    • Version: 0.000162 on 2024-04-25, with 47 votes
    • Previous CPAN version: 0.000159 was 6 months before
    • Author: EXODIST
  15. version - Structured version objects
    • Version: 0.9931 on 2024-04-27, with 21 votes
    • Previous CPAN version: 0.9930 was 7 months, 16 days before
    • Author: LEONT

(dlxxxvi) metacpan weekly report - App::perlimports

Niceperl

Published by Unknown on Sunday 28 April 2024 09:05

This is the weekly favourites list of CPAN distributions. Votes count: 75

Week's winner (+4): App::perlimports

Build date: 2024/04/28 07:04:22 GMT


Clicked for first time:


Increasing its reputation:

TPRC Call for volunteers

Perl Foundation News

Published by Amber Krawczyk on Saturday 27 April 2024 11:36


We hope you are coming to [The Perl and Raku Conference[(https://tprc.us/) in Las Vegas June 24-28! Plans are underway for a wonderful TPRC. But a conference of this type is only possible because of volunteers who give their time and expertise to plan, promote, and execute every detail. We need volunteers! You may have already volunteered to speak at the conference; if so, wonderful! If you are not presenting (or even if you are), there are many ways to help. We need people to set up and take down, to run the registration desk, to serve as room monitors, to help record the talks, and to just be extra hands. If you can spare some of your time for the sake of the conference, please fill out a volunteer form at https://tprc.us/tprc-2024-las/volunteer/ . We also welcome spouses and friends of attendees who might be coming along to Las Vegas to share the experience. We are offering TPRC "companion" tickets, for access to the social parts of the conference (food, drink, parties) but not the technical. Volunteers of at least one complete day, who sign up before the conference, will have companion access "comped". If you have questions about volunteering, please contact our TPRC Volunteer Coordinator: Sarah Gray sarah.gray@pobox.com

Grant Application: RakuAST

Perl Foundation News

Published by Saif Ahmed on Friday 26 April 2024 15:18


Another Grant Application from a key Raku develoer, Stefan Seifert. A member of the Raku Steering Council, Stefan is also an author of several Perl 5 modules including Inline::Python and (of course) Inline::Perl6. This Grant is to help advance AST or Abstract Syntax Tree. This is integral to Raku internals and allows designing and implementation of new language components, that can be converted into bytecode for execution by the interpreteter or "virtual machine" more easily that trying to rewrite the interpretter. Here is an excellent intro by Elizabeth Mattijsen


Project Title: Taking RakuAST over the finish line

Synopsis

There is a grant called RakuAST granted to Johnathan Worthington that is still listed as running. Sadly Johnathan has moved on and is no longer actively developing the Rakudo core. However the goal of his grant is still worthy as it is one of the strategic initiatives providing numerous benefits to the language. I have in fact already taken over his work on RakuAST and over the last two years have pushed some 450+ commits which led to hundreds of spectests to pass. This work was done in my spare time which was possible because I had a good and reliable source of income and could at times sneak in some Raku work into my dayjob. I can no longer claim that Raku is in any way connected to my day job and time invested in Raku comes directly out of the pool that should ensure my financial future. In other words, there's a real cost for me and I'd like to ask for this to be offset by way of a grant.

Benefits to Raku

This is mostly directly taken from the RakuAST grant proposal as the goal stays the same:

An AST can be thought of as a document object model for a programming language. The goal of RakuAST is to provide an AST that is part of the Raku language specification, and thus can be relied upon by the language user. Such an AST is a prerequisite for a useful implementation of macros that actually solve practical problems, but also offers further powerful opportunities for the module developer. For example:

  • Modules that use Raku as a translation target (for example, ECMA262Regex, a dependency of JSON::Schema) can produce a tree representation to EVAL rather than a string. This is more efficient, more secure, and more robust. (In the standard library, this could also be used to realize a more efficient sprintf implementation.)
  • A web framework such as Cro could obtain program elements involved in validation, and translate a typical subset of them into JavaScript (or patterns for the HTML5 pattern attribute) to provide client side validation automatically.

RakuAST will also become the initial internal representation of Raku programs used by Rakudo itself. That in turn gives an opportunity to improve the compiler. The frontend compiler architecture of Rakudo has changed little in the last 10 years. Naturally, those working on it have learned a few things in that time, and implementing RakuAST provides a chance to fold those learnings into the compiler. Better static optimization, use of parallel processing in the compiler, and improvements to memory and time efficiency are all quite reasonable expectations. We have already seen that the better internal structure fixes a few long standing bugs incidentally. However, before many of those benefits can be realized, the work of designing and implementing RakuAST, such that the object model covers the entire semantic and declarational space of the language, must take place. This grant focuses on that work.

Project Details

  1. Based on previous development velocity I expect do do some 200 more commits before the RakuAST based compiler frontend passes both Rakudo's test and the Raku spectest suites.
  2. Once the test suites pass, there will be some additional work needed to compile Rakudo itself with the RakuAST-frontend. This work will center around bootstrapping issues.

Considering the amount of work these items already will be, I would specifically exclude work targeted at synthetic AST generation, designs for new macros based on this AST, and anything else that is not strictly necessary to reach the goal of the RakuAST compiler frontend becoming the default.

Schedule

For the test and spectest suites I would continue my tried and proven model of picking the next failing test file and making fixes until it passes. Based on current velocity this will take around 6 months. However there's hope that some community members will return from their side projects and chime in.

Amount Requested

$10,000 for an estimated 200 hours of work.

Bio

I have been involved in Rakudo development since 2014 when I started development of Inline::Perl5 which brings full two-way interoperability between Raku and Perl. Since then I have helped with every major effort in Rakudo core development like the Great List Refactor, the new dispatch mechanism and full support for unsigned native integers. I have fixed hundreds of bugs in MoarVM including garbage collection issues, race conditions and bugs in the specializer. I have made NativeCall several orders of magnitude faster by writing a special dispatcher and support for JIT compiling native calls. I replaced a slow and memory hungry MAST step in the compilation process by writing bytecode directly, have written most of Rakudo's module loading and repository management code and in general have done everything I could to make Rakudo production worthy. I have also been a member of the Raku Steering Council since its inception.

Supporters

Elizabeth Mattijsen, Geoffrey Broadwell, Nick Logan, Richard Hainsworth

Explicit vs Implicit Hooks

domm (Perl and other tech)

Published on Monday 22 April 2024 09:00

At the Koha Hackfest I had several discussions with various colleagues about how to improve the way plugins and hooks are implemented in Koha. I have worked with and implemented various different systems in my ~25 years of Perl, so I have some opinions on this topic.

What are Hooks and Plugins?

When you have some generic piece of code (eg a framework or a big application that will be used by different user groups (like Koha)), people will want to add custom logic to it. But this custom logic will probably not make sense to every user. And you probably don't want all of these weird adaptions in the core code. So you allow users to write their weird adaptions in Plugins, which will be called via Hooks in the core code base. This patter is used by a lot of software, from eg mod_perl/Apache, Media Players to JavaScript frontend frameworks like Vue.

Generally, there are two kinds of Hook philosophies: Explicit Hooks, where you add explicit calls to the hook to the core code; and Implicit Hooks, where some magic is used to call Plugins.

Explicit Hooks

Explicit Hooks are rather easy to understand and implement:

package MyApp::Model::SomeThing;

method create ($args) {
    $self->call_hook("pre_create", $args);

    my $item = $self->resultset("SomeThing")->create( $args );
    
    $self->call_hook("post_create", $args, $item);
    
    return $item;
}

So you have a method create which takes some $args. It first calls the pre_create hook, which could munge the $args. Then it does what the Core implementation wants to do (in this case, create a new item in the database). After that it calls the post_create hook which could do further stuff, but now also has the freshly created database row available.

The big advantage of explicit hooks is that you can immediately see which hook is called when & where. The downside is of course that you have to pepper your code with a lot of explicit calls, which can be very verbose, especially once you add error handling and maybe a way for the hook to tell the core code to abort processing etc. Our nice, compact and easy to understand Perl code will end up looking like Go code (where you have to do error handling after each function call)

Implicit Hooks

Implicit hooks are a bit more magic, because the usually do not need any adaptions to the core code:

package MyApp::Model::SomeThing;

method create ($args) {
    my $item = $self->resultset("Foo")->create( $args );
    return $item
}

There are lots of ways to implement the magic needed.

One well-known one is Object Orientation, where you can "just" provide a subclass which overrides the default method. Of course you will then have to re-implement the whole core method in your subclass, and figure out a way to tell the core system that it should actually use your subclass instead of the default one.

Moose allows for more fine-grained ways to override methods with it's method modifiers like before, after and around. If you also add Roles to the mix (or got all in with Parametric Roles) you can build some very abstract base classes (similar to Interfaces in other languages) and leave the actual implementation as an exercise to the user...

Coincidentally, at the German Perl Workshop Ralf Schwab presented how they used AUTOLOAD and a hierarchy of shadow classes to add a Plugin/Hook system to their Cosmo web shop (which seems to be also wildly installed and around for quite some time). (I haven't seen the talk, only the slides

I have some memories (not sure if fond or nightmarish) of a system I build between 1998 and 2004 which (ab)used the free access Perl provides to the symbol table to use some config data to dynamically generate classes, which could then later by subclassed for even more customization.

But whatever you use to implement them, the big disadvantage of Implicit Hooks is that it is rather hard to figure out when & why each piece of code is called. But to actually and properly use implicit hooks, you will also have to properly structure your code in your core classes into many small methods instead of big 100-line monsters, which also improves testabilty.

So which is better?

Generally, "it depends". But for Koha I think Explicit Hooks are better:

  • For a start, Koha already has a Plugin system using Explicit Hooks. Throwing this away (plus all the existing Plugins using this system) would be madness (unless switching to Implicit Hooks provides very convincing benefits, which I doubt).
  • Koha still has a bunch of rather large methods that do a lot and thus are not very easily subclassed or modified by dynamic code.
  • Koha also calls plugins from what are basically CGI scripts, so sometimes there isn't even a class or method available to modify (though this old code is constantly being modernized)
  • Handling all the corner cases of implicitly called hooks (like needing to call next or SUPER) might be a bit to much for some Plugin authors (who might be more on the librarian-who-can-code-a-bit side of the spectrum then on dev-who-happens-to-work-with-libraries)
  • A large code base like Koha's, which is often worked on by non-core-devs, needs to be greppable. But Implicit Hooks are basically invisible and don't show up when looking through the Core code.
  • But most importantly, because Explicit Hooks are boring technology, and I've learned in the last 10 years that boring > magic!

Using implicit hooks could maybe make sense if Koha

  • is refactored to have all it's code in classes that follow a logic class hierarchy and uses lots of small methods (which should be a goal in itself, independent of the Plugin system)
  • somebody comes up with a smart way to allow Plugin authors to not have to care about all weird corner cases and problems (like MRO and diamond inheritance, Plugin call order, the annoying syntax of things like around in Moose, error handling, ...).

An while it itches me in the fingers to do come up with such a smart system, I think currently dev time is better spend on other issues and improvements.

P.S.: I'm currently traveling trough Albania, so I might be slow to reply to any feedback.

Last week we (aka HKS3) attended the Koha Hackfest in Marseille, hosted by BibLibre. The hackfest is a yearly meeting of Koha developers and other interested parties, taking place since ~10 years in Marseille. For me, it was the first time!

Things I learned (and other notes)

  • While I still don't like traveling by plane, the route Vienna - Marseille is very hard to travel by train (or bike).
  • Airbnb hosts come up with the weirdest ways to allow guests to access their apartment, which of course fail spectacularly on Sunday at 20:30. (We had to call a number, which should then automatically unlock the door. Didn't work, so the owner called somebody to open the door for us. And told us to basically reboot the system by toggling the main breaker. The system then worked for the rest of our stay).
  • I still like Cidre and Galettes a lot.
  • Do not underestimate what you can do with a shared online spreadsheet, a few tabs in said spreadsheet, and some smart formulas: No need for a fancy conference orga tool.
  • There is no competition who will eat the most from the overflowing shared sweets tables featuring nice (but unhealthy) stuff brought by all the attendees. I think I still tried to win.
  • Once you have koha-testing-docker up and running, sending patches and signing them off is not too hard.
  • I still find the process not too easy (and it can take quite some time, making "drive by commits" nearly impossible, but then Koha is a piece of software that is distributed and installed onto thousands of (different) servers, so it unfortunately does make sense to take a bit more care.
  • We had some interesting discussions on various ways to implement Plugins and Hooks, mostly about explicit hooks (sprinkling the code with method calls to various named hooks) vs implicit hooks (using Perl magic to wrap methods). I'll post a followup blog post on that soon. Here are my extended thoughts on that subject.
  • I still like Moules Frites and Sirup, but find Diabolo (Sirup with Lemonade) too sweet (and I like sweet!)
  • Another nice thing about Marseille: When you forget your jacket at the venue, and the temperature drops from nice to cold, you can drop into a Kilo Shop and get a cheap (and weird) second hand jacket.
  • I learned how to spell Marseille!
  • Wow, the cheese lunch...
  • The table football ("Wuzzler", as we call it) has a very weird layout; using a soft ball has the advantage that it's less noisy (but plays like crap). Tomas was a fierce adversary :-)
  • I learned that koha-dpkg-docker exists (a container to build Debian packages of Koha), but could not get it to work. Yet!
  • The last day of Ramadan and Eid al-Fitr causes a lot of happy activity in the town center.
  • It's nice to have a harbour as a town center.
  • Andreii again tried to get the Koha people to join the Perl community and the Perl community to start to care about Koha, eg by inviting Koha devs to submit talks to the upcoming Perl and Raku Conference in Las Vegas and inviting Perl people to the upcoming Koha Con in Montréal. So if you identify as one or the other (or both!) and want to attend one of those events, please do so! And maybe also submit a talk!!
  • Very little sleep, drinking coke instead of water and not being young anymore is not a very good combination, which caused me to have to take half a day off on Wednesday.
  • Getting to know the actual people behind email addresses and IRC handles helps a lot.
  • I got told the not-so-secret story behind the name ByWater by their exceptionally friendly and generous CEO Brendan Gallagher over beer and cider that for a change we paid for.
  • Fridolin Somers explained why the ElasticSearch configuration / mappings exist in two data stores (the DB and a yaml file), and why this probably cannot be avoided: For bulk changes (when you manage lots of libraries) the yaml file is easier than manually clicking through the UI; they don't trust people who have access to that UI to not fuck up the mappings (then IMO access to this should be more restricted). I still thing that a change to the DB via UI should be reflected in the yaml file, especially as there is a big fat button in the UI that will reset whatever is in the DB with the yaml file. To be discussed...
  • The colleagues from KIT are also working on Elasticsearch and fixed a very annoying bug with the UI: Ability to add search fields from UI. We used that as training bug to learn the sign-off process. And by now it's even pushed to 24.05, yay!
  • When a bunch of stakeholder meet in a room and want to cooperate, complex decisions can be found quickly (switching from IRC to Mattermost for Koha Chat)
  • When this decisions is not what you preferred (Matrix/Element), but pushing your preference would probably only work if you volunteered a lot of time and effort, it's wiser to accept it. (Plus, Mattermost has a few features that Element lacks)
  • While trying to sign off one bug fix, it can happen that you discover two more (only one reported yet, though)
  • You have to apply for the job of QA person (i.e. to check that each bug/feature actually works before it's committed) and have to win a vote. This might explain why it often takes very long to get a patch into Koha, as there are very few people on the QA team. I'm only very slowly getting used to this (in my eyes) very slow and cumbersome process, but I guess "move fast and break things" is not something libraries care about..
  • Update: There are actually a lot of people on the QA team , I was looking at the wrong list. They do a great job! But it could always be more members!!
  • Katrin Fischer is a walking Koha encyclopedia and happily shares her knowledge.
  • Having a beach withing walking distance (barely, but still) is very nice. Especially if the weather turns out sunny, warm and not windy. And the water cold, but manageable.
  • While I initially found the concept of high end food courts a bit strange, they are very nice for a large group of people to randomly show up. Also, I can find some weirder food ("African" sweet potatoe waffles with fried chicken and plantain (fried bananas)) while others can have their boring burgers and pizzas.
  • If I had known before that joubu not only QAs Koha, but also random blog posts, the inital verison of this post would have containted much less errors!

Achievements

  • I quickly hacked together a Vue3 Island Architecture Prototype showing how you can load distinct components that are distributed in one vue app into existing backend rendered HTML, thus for example making it easy to reuse the navbars, auth etc from the backend rendered app, while still having a shared router and state in the Vue app.
  • We finally got our GeoSearch signed off and passed QA. Thanks Nick & Martin!
  • We signed off a few bugs / features, finally learning (for good, I hope) how to work with KTD and git-bz.
  • eg this one Add a plugin hook to modify patrons after authentication, which was a pain to set up, because the Keycloak SSO integration has to be manually configured in KTD.
  • The German speaking attendees decided to try to set up a Koha-DACH German language hackfest-y event in autumn.
  • I added a new flag, --dbshell to KTD for easy access to the DB shell.
  • I tried a different approach to get Plack hot reload into KTD, but that's still in discussion.
  • Probably more..

Thanks

Thanks to BibLibre and Paul Poulain for organizing the event, and to all the attendees for making it such a wonderful 4 days!