Comments (4)
I heard on Twitter that perl 5.27.8 just reverted this change, at least for now. We'll see.
from autobox.
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.:
- https://metacpan.org/pod/Class::Builtin
- https://metacpan.org/pod/Data::Object
- https://metacpan.org/pod/Object::Hybrid
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.
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.
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)
- t/pod.t returns in 2.86 HOT 1
- version.pm must be used to support version tuples on perl 5.8 HOT 3
- Spelling error HOT 1
- New versioning format breaks cpanm HOT 9
- Does not work with Parallel::ForkManager on Windows HOT 3
- Documentation needs to be clearer about consumption HOT 1
- Build fails with Perl 5.25 HOT 2
- Fails tests without '.' in @INC HOT 1
- Bareword OP_METHOD invocants not exempted from autoboxing HOT 1
- Autoboxing fails under the perl debugger in perl >= 5.22 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autobox.