Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^6: Removing AUTOLOAD from CGI.pm (flexibility?)

by LanX (Saint)
on Feb 24, 2015 at 16:42 UTC ( [id://1117684]=note: print w/replies, xml ) Need Help??


in reply to Re^5: Removing AUTOLOAD from CGI.pm
in thread Removing AUTOLOAD from CGI.pm

> it was future proofed! You could call CGI->wibble and get a <wibble> tag.

I wasn't able to reproduce this without explicitly importing "wibble"

DB<100> use CGI qw(:all wibble) DB<101> wibble => "<wibble />"

but

DB<100> use CGI ':all' DB<101> $x=CGI->new() DB<102> $x->wibble() Undefined subroutine CGI::wibble at (eval 24)[multi_perl5db.pl:644] line 2

So autoloading makes not much sense in this case.

It doesn't make the code more flexible it only delays the installation, which could already happen in the importer.

Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)

PS: Je suis Charlie!

Replies are listed 'Best First'.
Re^7: Removing AUTOLOAD from CGI.pm (flexibility?)
by leej (Scribe) on Feb 25, 2015 at 07:19 UTC

    You had to use :any to get this behaviour:

    $ pmvers CGI 3.59 $ perl -E 'use CGI qw/:any/; say CGI->new->wibble({foo=>"bar"},"baz")' <wibble foo="bar">baz</wibble>

      > You had to use :any to get this behaviour:

      Didn't see this, because :any is not documented in CGI , though -any is as a "pragma" (and mentioned in your blog-post)

      There is also a mention of -compile , which means AUTOLOAD isn't needed to create the HTML-DSL.

      IOW you could¹ get rid of AUTOLOAD without deprecating HTML-subs, just by making -compile the default.

      But if you meant to deprecate the -autoload pragma, this seems to be a good idea.

      Installing an AUTOLOAD into the importing namespace sounds like a very hazardous hack.

      Cheers Rolf
      (addicted to the Perl Programming Language and ☆☆☆☆ :)

      PS: Je suis Charlie!

      ¹) I don't say "should" :)

      update

      After reading your blog-post again (>4th time) I'm puzzled. You only say you are disabling AUTOLOAD but not that you are deprecating precompiled HTML-subs in general.

      Did I misunderstand you? Maybe you could clarify.

        > After reading your blog-post again (>4th time) I'm puzzled. You only say you are disabling AUTOLOAD but not that you are deprecating precompiled HTML-subs in general. Did I misunderstand you? Maybe you could clarify.

        That's correct. AUTOLOAD is gone but the HTML generation functions remain. I had to add/tweak the code to generate the HTML functions. It cleans up the code hugely.

        Here's the relevant commit. It's rather large so github doesn't show the full delta. There are a few other related commits later on, they all have #162 in the commit message.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1117684]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (1)
As of 2024-09-11 10:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The PerlMonks site front end has:





    Results (13 votes). Check out past polls.

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.