Giter Club home page Giter Club logo

Comments (4)

akarelas avatar akarelas commented on June 19, 2024 1

I heard on Twitter that perl 5.27.8 just reverted this change, at least for now. We'll see.

from autobox.

chocolateboy avatar chocolateboy commented on June 19, 2024

No, it's not possible. As described here, autobox just lexically overrides the arrow operator. It doesn't bless primitives into objects, so overloading, or any other kind of "magic" which depends on values being blessed, doesn't work.

I'm not sure from your gist what missing functionality you're trying to add (and I can't reproduce that error with perl 5.26.1, the latest stable release).

If you're looking to use a sane/simple version of smart-matching on legacy perls, I used to use this:

If you want to promote an array to an object whose package you can add a custom ~~ overload to, there are several packages for that e.g.:

And there are a couple of packages which export functions which "cast" arrays, arrayrefs and code blocks into matcher objects which DWYM e.g.:

from autobox.

akarelas avatar akarelas commented on June 19, 2024

Thanks for your reply. The error I described above only occurs on Perl 5.27.7 and later, where the ~~ operator is undefined except on objects that overload it.

from autobox.

chocolateboy avatar chocolateboy commented on June 19, 2024

P.S.

I wonder if autobox could be modified to handle ~~ as well

Yes, it probably could... Though I'm not sure it should be. (Why just that operator? What about the others? Why not just use Ruby? :-))

I haven't investigated, but I doubt there's a central hook that can be intercepted to check for overloads on all operands, so one would need to be written for every operator.

That said, I imagine it would be possible (and possibly useful) to build a module for a single operator like ~~ (e.g. autobox::smartmatch) which leverages autobox's "type system" to DWYM.

from autobox.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.