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

Perl - nice to have features

Thread Next
From:
Branislav Zahradník
Date:
November 28, 2022 11:17
Subject:
Perl - nice to have features
Message ID:
CAB=rbO=NDQXTywGU1aMwA-h4R=yiJTa+uvqbABL0XFsqWArSKw@mail.gmail.com
Hi,

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,
Brano

- 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
next
call will continue (when called with same parameters)

POC using current tools available:
https://gist.github.com/happy-barney/e40fef7a56df4cbd309e03bcf8ee9503

- ability to postpone evaluation of named group (using modifier P in
example)
```
# 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 (
  (?(DEFINE)
     (?<Qualified_Identifier> (?<qualification> ...) (?<identifier>) ) )
     ...
  )
)x;

# %+ 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 { ... }
vs.
around foo => sub { ... };

subtest foo { }
vs
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&`
eg:
```
sub Moo::extend :BEGIN { ... }

# Usage:
extend Foo::;
vs
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.
eg:
```
sub foo {
=pod foo
...
=cut
}

=pod
=head1 METHODS
R<foo>
=cut
```

additional features:
- support grouping
  =pod foo :methods
  R<:methods>
- support ordering
  R<:methods|order=alpha>
- 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


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