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

Pre-RFC: a `module` keyword

Thread Next
From:
Ovid via perl5-porters
Date:
January 24, 2022 19:21
Subject:
Pre-RFC: a `module` keyword
Message ID:
386417877.927224.1643052041839@mail.yahoo.com
I've been thinking about this a lot and I wanted to run an idea past P5P. Corinna tremendously cleans up Perl's OOP capabilities. It would be nice to have something like that for procedural code. I have no sponsor for this, but I was thinking about a `module` keyword. It would complement Corinna syntax and look something like this:

    module Some::Utilities :version(3.14) {
        # all subs with an :export tag can be imported individually

        # use Some::Utilities ':strings';
        sub make_slug :export(strings) ($name) {
            ...
        }

        # use Some::Utilities ':numbers';
        sub constrain :export(numbers) ( $min, $num, $max = undef ) {
            ...
        }

        # use Some::Utilities ':numbers';
        sub weighted_pick :export(numbers) ($weight_for) {
            ...
        }
    
        # cannot be exported
        sub _binary_range ( $elem, $list ) {
            ...
        }
    }

Benefits:

* Postfix block lexically scopes changes
* Strict, warnings, utf8 source, signatures, and "no feature 'indirect'" by default
* :export is handled natively leaving the import() free for other uses
* Yields a `1` to avoid needing to add `1` at the end of every file.

Deliberately limited in scope to make it smaller and easier to implement. I believe that with `module` and `class`, we have a solid foundation for releasing Perl 7.

Best,
Ovid
-- 
IT consulting, training, specializing in Perl, databases, and agile development
http://www.allaroundtheworld.fr/. 

Buy my book! - http://bit.ly/beginning_perl

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