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

Perl - nice to have features

Thread Next
Branislav Zahradník
November 28, 2022 11:17
Perl - nice to have features
Message ID:

following is short summary of my list of nice to have features

if you want some of them as preRFC, just let me know

Best regards,

- support for thunk
thunk will act like tie but will support only FETCH and will be executed
only once
(ie will replace value)

related builtin method: is_unresolved_thunk (tied may be sufficient)
Ref::Util queries should work on thunk without resolving it, eg:
my $arrayref = thunk \@ { return [] };

- support for yield
will act as return but will also set temporary label (after yield) where
call will continue (when called with same parameters)

POC using current tools available:

- ability to postpone evaluation of named group (using modifier P in
# will not fail (unlike currently)
my $regex = qr ( (?&Identifier) )xP;

# will fail unless $GRAMMAR defines (?<Identifier>)
while ($data =~ m ( $regex $GRAMMAR )x) { ... }

- ability to pick named group's named matches
my $GRAMMAR = qr (
     (?<Qualified_Identifier> (?<qualification> ...) (?<identifier>) ) )

# %+ is empty
m ( (?&Qualified_Identifier) $GRAMMAR );

# %+ will contain qualification and identifier (pseudosyntax)
m ( (?&(*)Qualified_Identifier) $GRAMMAR )x;

# %+ will contain only identifier
m ( (?&(identifier)Qualified_Identifier) $GRAMMAR )x;

# %+ will contain name and qualification
m ( (?&(name=identifier,qualification)Qualified_Identifier) $GRAMMAR )x;

- ability to query available labels
I often use pattern `goto $computed_label` for which I have to build and
maintain hash of available
labels. It will be nice to have something like

goto $_ if local $_ = builtin::label_exists ($computed_label);

- support prototype `i&`
to be able to write functions acting like a `sub`, eg:
around foo { ... }
around foo => sub { ... };

subtest foo { }
subtest foo => sub { ... };

with additional nice to have:
- signatures
- attributes
- array of identifiers

- ability to specify phase when function is executed
related to prototype `i&`
sub Moo::extend :BEGIN { ... }

# Usage:
extend Foo::;
BEGIN { extend Foo:: }

- quoted identifier mechanism
Introduce new (eg: `qi`) quoting to allow any character in identifier, eg:
sub qi<this is function name> { ... }
$self->qi<this is function name> (...)

Usage will be mostly for functions communicating with outside word, eg:
(with usage of `i&` prototype)
get qi</api/endpoint> { ... }
subtest qi<should do this and that> { ... }

- named references in pod

Currently there are two documentation strategies:
- inline pod - where documentation layout dictates layout of code
- separated pod - where documentation is outside of documented code

Often code layout needs different layout than documentation layout, but
benefits from
having inline documentation (regardless whatever whoever thinks about
inline documentation)

Referenced pod will allow (similar to eg: yaml references) to define inline
documentation section
and expand it in documentation.
sub foo {
=pod foo

=head1 METHODS

additional features:
- support grouping
  =pod foo :methods
- support ordering
- support heading modification
  R<:methods|head=+1> ... every =headN will be transformed into =headN+1
  R<:methods|head=item> .. every head will be transformed into =item

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About