develooper Front page | perl.perl5.porters | Postings from January 2022

Re: Pre-RFC: Policies

Thread Previous | Thread Next
From:
Tony Cook
Date:
January 27, 2022 20:53
Subject:
Re: Pre-RFC: Policies
Message ID:
20220127205334.GL3065@venus.tony.develop-help.com
On Thu, Jan 27, 2022 at 06:22:06PM +0000, Ovid via perl5-porters wrote:
> I want to make it easier to reduce boilerplate.
> 
> One of my clients had a rule that every Perl module has a standard set of boilerplate at the top of every Perl package/script. I changed that to:
> 
>     use Client::Policy;
> 
> That made life much easier. I do this a lot for clients and I don't want to keep doing that. However, there were fiddly bits in writing that module. I'd rather write this:
> 
>     use feature 'policy';
>     policy;
> 
> And that reads a .perlpolicy file and automatically injects its contents into the current code.
> 
> So if .perlpolicy contains this:
> 
>     use v5.26;
>     use warnings;
>     use feature "signatures';
>     no warnings 'experimental::signatures';
>     use Carp qw(carp croak);
> 
> You don't have to write that every time.
> 
> However, we need to consider how the .perlpolicy file is located, and handling the case where you might want different policies for different parts of your code. For example, for Tau Station, we have `Veure::Module`, `Veure::Moose`, and `Veure::Script` depending on our needs. Or if you update Perl, maybe have incremental policies based on the version of Perl?
> 
>     policy; # default
>     policy 'script';
>     policy 'Moose';
> 
> This solves a common problem, but I have not yet thought out all of the implications, so I'd love feedback.

I don't see the advantage over `use Client::Policy;`, `use Client::Policy::Script;'.

Or even `use LocalPolicy 'script';` if the module was more complex.

In both cases the policy is coming from a local file, and with such a
feature (as described) you'd be limited to the mechanisms the feature
provides, while a module is more flexible.

The feature could be made to load the Client::Policy module for extra
flexibility but then you're back where you started.

Tony

Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About