develooper Front page | perl.perl5.porters | Postings from June 2016

[perl #122607] Call on object overloading &{} returned by a constant-> fails to compile

From:
=?UTF-8?B?T2xpdmllciBNZW5ndcOp?= via RT
Date:
June 28, 2016 10:24
Subject:
[perl #122607] Call on object overloading &{} returned by a constant-> fails to compile
Message ID:
rt-4.0.18-1090-1467109469-789.122607-15-0@perl.org
Le Dim 24 Aoû 2014 13:55:26, dolmen a écrit :
> # == This works ==========
> my $x = CONST_CLS;
> say( $x->("OK") );
> # ========================
> 
> # == This doesn't works ==
> # Compile fails: "Constant is not a CODE reference"
> #say( CONST_CLS->("OK") );
> # ========================

Here are two workarounds I use for perl < 5.21.4:

    say do{ CONST_CLS }->("OK");
    say &{ +CONST_CLS }("OK");


See Term::Chrome as real world use of &{} overloading and "use constant" combination.
https://metacpan.org/pod/Term::Chrome

---
via perlbug:  queue: perl5 status: resolved
https://rt.perl.org/Ticket/Display.html?id=122607



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