in reply to Re^3: Using CORE:: with autobox
in thread Using CORE:: with autobox
The next issue that I found with autobox is that all your hashes and arrays must be references (despite what the POD docs seem to indicate).Yes, the receiver must be a scalar i.e. (by default) a string, number or reference. If there's somewhere in the docs that makes this unclear or ambiguous, please let me know and I'll fix it. Note that there is a module by Scott Walters, Perl6::Contexts, that allows methods to be called on plain (i.e. non-reference) hashes and arrays.
And then the last problem I have with it is that the pragma is not lexically scoped.I apologise if I gave that impression. It's always been lexically scoped and works independently of the lexical pragma. There are a bunch of tests that verify its "lexical correctness" in the test suite.
scope1.pl:
01: $| = 1; 02: 03: sub SCALAR::uc { uc $_[0] } 04: 05: { 06: use autobox; 07: print "hello, world!"->uc; 08: } 09: 10: print "hello, world!"->uc;
> perl -l scope1.pl
scope2.pl:HELLO, WORLD!
Can't locate object method "uc" via package "hello, world!" (perhaps you forgot to load "hello, world!"?) at scope1.pl line 10.
01: $| = 1; 02: 03: sub SCALAR::uc { uc $_[0] } 04: sub test { $_[0]->uc } 05: 06: { 07: use autobox; 08: print "hello, world!"->uc; 09: test("hello, world!"); 10: }
> perl -l scope2.pl
scope3.pl:HELLO, WORLD!
Can't locate object method "uc" via package "hello, world!" (perhaps you forgot to load "hello, world!"?) at scope2.pl line 4.
01: $| = 1; 02: 03: sub SCALAR::uc { uc $_[0] } 04: 05: { 06: use autobox; 07: print "hello, world!"->uc; 08: 09: { 10: no autobox; 11: print "hello, world!"->uc; 12: } 13: }
> perl -l scope3.pl
At any rate, don't trust my poorly and hastily written emails; trust my poorly and hastily written docs and tests :-)HELLO, WORLD!
Can't locate object method "uc" via package "hello, world!" (perhaps you forgot to load "hello, world!"?) at scope3.pl line 11.
chocolateboy
|
---|