in reply to Re: Dumping regexp for Perl versions earlier than 5.14
in thread Dumping regexp for Perl versions earlier than 5.14

In my module (DateTime::Format::Alami), I'm building a big regex from potentially hundreds of smaller bits (which will be retrieved from a method and applied some preprocessing). This regex won't change between runs, so in order to save startup time, I'm precomputing it during dist build time. (I don't know how big the saving will be though, so perhaps this is premature optimization.)

There's another use-case where I put regex literal into the built source code with Dist::Zilla: inserting code-generated argument validation code. I do this in some cases where I want the autogenerated argument validation code to be embedded directly into the source code and not generated/called dynamically during runtime (and thus usually adds another subroutine call level or startup overhead time, because in my case the argument validation code generator has quite a bit of startup time). An example:

sub foo { my ($arg1, $arg2) = @_; # INSERT CODE VALIDATION HERE ... }

During build, a Dist::Zilla plugin will fill in the code validation routine:

sub foo { my ($arg1, $arg2) = @_; defined($arg1) or die "arg1 is required"; $arg1 =~ qr/\A\w+\z/ or +die "arg1 must be alphanums only"; defined($arg2) or die "arg2 is req +uired"; # INSERT CODE VALIDATION HERE ... }

I hope that clears up things a bit.

And even if the above two use-cases are not commonly had with other programmers, I'm still curious about the problem of handling regex stringification backward-incompatibility in Perl 5.14.