summaryrefslogtreecommitdiff
path: root/lib/overload.pm
Commit message (Collapse)AuthorAgeFilesLines
* Prefer scalar assignment to get caller's first return valueRichard Leach2023-02-221-3/+3
| | | | | | | | | | | | | | | | | | | | | | | Multiple forms of syntax can be used to obtain a package name from `caller`, which emits this as its first return value, and assign that name to a lexical scalar. The following each achieve the same result, but with varying efficiency: * `sub callme { my $package = caller(2); ...}` * `sub callme { my ($package) = caller(2); ...}` * `sub callme { my $package = (caller(2))[0]; ...}` In the first example, `pp_caller` determines only the package name and pushes it to the stack. In the other two examples, the other 10 of `caller`'s return values are calculated and pushed onto the stack, before being discarded. This commit changes non-CPAN-first instances of the latter two forms in core to the first form. Note: There is a special exception to the equivalence described above, when caller is use in list context within the DB package. Such a usage instance in regen/warnings.pl therefore remains unchanged.
* overload: bump versionGraham Knop2022-10-241-1/+1
|
* overload: only disable builtin warnings where blessed is calledGraham Knop2022-10-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | Until recently, overload did not enable or disable any warnings. Instead, it would rely on the value of $^W, or the -w flag. When switching to use the builtin::blessed function, the code was changed to disable 'experimental::builtin' warnings. Since no other warnings are changed, the current active warning set is combined with this one disabled category, and baked in for the entire module. The currently active warning set is determined by $^W, so whatever its value was when overload was compiled would get baked in, and any runtime changes to $^W would no longer have any impact. The particular warning that would most commonly be emitted by overload is the sub redefinition warning, in case an overload was being overwritten. Various modules, such as JSON::PP and Cpanel::JSON::XS, were expecting to be able to overwrite overloads without any warnings. They would set $^W to false to prevent them. After the "no warnings 'experimental::builtin';" line was added, it became impossible to disable these warnings at runtime. Move the disabling of the experimental warnings to a smaller scope. This means that the rest of the module is restored to its previous state of having warnings controlled by $^W.
* overload: remove localizing of error varibles when not loading a moduleGraham Knop2022-10-241-2/+0
| | | | | | Localizing $@ and $! was added when the code was loading Scalar::Util at runtime. We're no longer loading any modules in this part of the code, so we don't need to localize anything.
* overload: clean up whitespaceGraham Knop2022-10-241-360/+364
| | | | | The file was partly using 2 space indents, partly using 4 space indents, and occasionally tabs. Standardize on 4 space indents using spaces.
* Augment overload::Method docsHugo van der Sanden2022-02-031-0/+3
|
* Fix bundled .pm files for experimental::builtin warningsPaul "LeoNerd" Evans2022-01-251-1/+2
|
* Use builtin::blessed() in overload.pm rather than using Scalar::UtilPaul "LeoNerd" Evans2021-12-141-4/+3
|
* Fix enough code to get make test_prep working with -dDusedefaultstrictTodd Rinaldo2020-10-131-6/+9
| | | | | | | | | This change fixes enough code that it's possible to run make test_prep when perl is compiled with -Dusedefaultstrict. There are 2 caveats to this: - Does not address XSLoader/DynaLoader already submitted in another PR. - Does not address cpan/Pod-Usage or cpan/Text-Tabs which continue to be outstanding upstream.
* Change some link pod for better renderingKarl Williamson2020-08-311-2/+2
| | | | C<L</foo>> renders better in places than L</C<foo>>
* lib/overload.pm: Use L</Foo Bar>, not L<Foo Bar>Karl Williamson2019-05-251-15/+15
|
* Update docs wrt bitwise opsFather Chrysostomos2017-12-311-2/+2
|
* revert smartmatch to 5.27.6 behaviourZefram2017-12-291-3/+28
| | | | | | | | | | | | | The pumpking has determined that the CPAN breakage caused by changing smartmatch [perl #132594] is too great for the smartmatch changes to stay in for 5.28. This reverts most of the merge in commit da4e040f42421764ef069371d77c008e6b801f45. All core behaviour and documentation is reverted. The removal of use of smartmatch from a couple of tests (that aren't testing smartmatch) remains. Customisation of a couple of CPAN modules to make them portable across smartmatch types remains. A small bugfix in scope.c also remains.
* update doc in lib/ about smartmatchZefram2017-11-221-28/+3
|
* overload.pm: add a missing 'exists'Dan Collins2016-12-261-2/+2
| | | | | | | | 607ee4356 changed the hash of permitted ops from having '1' as a value to having undef as a value. This also changed one of the warning points from checking for truthiness to existence. However, a second warning was accidentally left checking for truthiness. This commit fixes that oversight, and adds a regression test for warnings in this case.
* Speed up compilation of overload.pm a smidge.James Raspass2016-09-281-5/+3
| | | | | | | | | | | | | | | | | | Measured with the following crude perl script calling perf. Perl is in there to get a rough baseline cost of starting perl: print 'PERL', (`perf stat -r100 perl -e 1 2>&1`)[10]; print 'OLD ', (`perf stat -r100 perl lib/overload.pm 2>&1`)[10]; print 'NEW ', (`perf stat -r100 perl lib/overload2.pm 2>&1`)[10]; Produced the following results on my machine: PERL 5,800,051 instructions # 1.05 insns per cycle ( +- 0.06% ) OLD 14,818,995 instructions # 1.16 insns per cycle ( +- 0.03% ) NEW 14,696,974 instructions # 1.16 insns per cycle ( +- 0.03% ) While the numbers did fluctuate between runs, the new code was consistently faster.
* document that we may add more overloaded ops over timeRicardo Signes2015-05-081-1/+2
|
* overload.pm: Document fifth arg for &|^~Father Chrysostomos2015-01-311-2/+11
|
* overload.pm: TypoFather Chrysostomos2015-01-311-1/+1
|
* overload.pm: Document &. etc.Father Chrysostomos2015-01-311-6/+6
|
* Increase $overload::VERSION to 1.25Father Chrysostomos2015-01-311-1/+1
|
* overload.pm: Add string-specific bitopsFather Chrysostomos2015-01-311-4/+4
|
* overload.pm: Removed an unused variableBrian Fraser2014-10-311-2/+2
|
* Increase $overload::VERSION to 1.23Father Chrysostomos2014-09-091-1/+1
|
* Remove redundant check from overload.pmFather Chrysostomos2014-09-091-1/+1
| | | | | I added this in ca6102577e. It is silly to check ref $sub a few lines after $sub = \&....
* Document that range operator '..' can not be overloaded.Moritz Lenz2013-04-141-1/+5
| | | | | Also document that this means that ranges and bigint.pm do not mix perfectly. Bump version numbers.
* Fix various minor pod issuesKarl Williamson2013-01-241-2/+2
| | | | | These were all uncovered by the new Pod::Checker, not yet in core. Fixing these will speed up debugging the new Checker.
* propagate context into overloads [perl #47119]Jesse Luehrs2012-06-281-4/+1
| | | | | | | | | | | | | | | | | amagic_call now does its best to propagate the operator's context into the overload callback. It's not always possible - for instance, dereferencing and stringify/boolify/numify always have to return a value, even if it's not used, due to the way the overload callback works in those cases - but the majority of cases should now work. In particular, overloading <> to handle list context properly is now possible. For backcompat reasons (amagic_call and friends are technically public api functions), list context will not be propagated unless specifically requested via the AMGf_want_list flag. If this is passed, and the operator is called in list context, amagic_call returns an AV* holding all of the returned values instead of an SV*. Void context always results in amagic_call returning &PL_sv_undef.
* [perl #113050] Put fallback back under "()"Father Chrysostomos2012-05-231-4/+5
| | | | | | | | | | | | | | Unfortunately, there is code all over CPAN that assumes fallback is stored under the "()" stash entry. And that code also assumes that the overloadedness flag (the existence of the CV) is in the same spot. So much for encapsulation. This commit changes overloading itself to use a different key, "((", while having it search for "()" first, and then "((" only if "()" is not found, to preserve compatibility with encapsulation-breaking code. So the "((" key will only be used by gv.c if there is no fallback value specified at all.
* overload.pm: Allow :: in method namesFather Chrysostomos2012-05-211-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | According to overload’s documentation, ‘[v]alues specified as strings are interpreted as method names.’ But it behaves differently if the string contains a double colon: use overload q\""\=>"bar::baz"; @bar::ISA = foo; sub foo::baz{a} warn bless[] __END__ Undefined subroutine &bar::baz called at - line 4. But apostrophes work as documented: use overload q\""\=>"bar'baz"; @bar::ISA = foo; sub foo::baz{a} warn bless[] __END__ a at - line 4. I can’t see how the treatment of ::, introduced in a60067777, is not a bug, though the method logic looks intentional: + if (not ref $sub and $sub !~ /::/) { I suspect it was one of those things that was just not thought through. The pre-a60067777 logic was in gv.c, and treated strings containing package separators just like any other strings: switch (SvTYPE(sv)) { default: if (!SvROK(sv)) { if (!SvOK(sv)) break; gv = gv_fetchmethod(stash, SvPV(sv, na)); if (gv) cv = GvCV(gv); break; } cv = (CV*)SvRV(sv);
* overload.pm: This warning exists nowFather Chrysostomos2012-05-211-10/+0
|
* Update overload docsFather Chrysostomos2012-05-211-24/+7
|
* Make ‘no overload’ also warn about invalid argsFather Chrysostomos2012-05-211-0/+2
|
* overload.pm: Don’t touch %OVERLOAD’s dummy entryFather Chrysostomos2012-05-211-2/+0
| | | | | | | | | | | Now that mro_method_changed_in (triggered by the ‘*{$package . "::()"} = \&nil;’ assignment) causes overloadedness to be checked the next time a overloaded operation occurs, it is not nec- essary to trigger %OVERLOAD’s magic explicitly. This also means that PL_amagic_generation is not incremented any more. Unfortunately, we cannot eliminate it, as there are XS modules that expect to increment it themselves to mark their caches as stale.
* Make overloaded classes inherit fallbackFather Chrysostomos2012-05-211-11/+11
| | | | | | | | | | | | | | | | | | | | | | | | Before this commit, only classes that had no overloading defined could inherit the fallback from other classes. If a subclass wanted to override a single overload setting, it would have to specify the fall- back value explicitly, to avoid implying fallback=>undef. We do this by separating the fallback value from overloadedness itself, so it is possible to have a class that is overloaded, but with no fallback value. Previously, the ‘()’ stash entry was used for two purposes. It had a sub in it so it could be found using usual method lookup mechanims. The failure to find any such method would be taken for efficiency’s sake to mean that there was no overloaded, and the search for methods could end early. The scalar slot contained the fallback entry itself. To preserve the effiency, we still use &{"()"} to indicate that there is overloadedness. Fallback now uses its own entry, named ‘(fallback’. Since it has to be special-cased anyway, there is no need to add it to regen/overload.pl.
* Increase $overload::VERSION to 1.19Father Chrysostomos2012-05-211-1/+1
|
* Increase $overload::VERSION to 1.18Father Chrysostomos2012-01-241-1/+1
|
* In overload::AddrRef, use ‘no overloading’Father Chrysostomos2012-01-241-11/+2
| | | | This speeds this up by about 13 times.
* overload.pm: Smaller indents for long linesFather Chrysostomos2012-01-181-6/+6
|
* overload.pm: spaces after dots; wording tweakFather Chrysostomos2012-01-181-16/+17
|
* Document new overload warning in overload.pmFather Chrysostomos2012-01-181-0/+5
| | | | as well as perldiag.
* overload.pm: Doc tweaksFather Chrysostomos2012-01-181-1/+1
| | | | This sentence got mangled somehow, somewhen.
* In overload::ov_method, use ‘no overloading’Father Chrysostomos2012-01-181-3/+2
| | | | Using this instead of Scalar::Util makes things marginally faster.
* Lower $overload::VERSION to 1.17Father Chrysostomos2012-01-161-1/+1
| | | | It doesn’t need to be increased twice between releases.
* overload.pm: Combine two loopsFather Chrysostomos2012-01-161-3/+2
| | | | It should go faster if we only iterate through %arg once.
* overload.pm: Put invalid arg warning in "overload" categoryFather Chrysostomos2012-01-161-1/+1
| | | | Existing overload warnings work that way.
* Suppress ‘useless’ warning in overload.pmFather Chrysostomos2012-01-161-1/+1
|
* Emit a warning if an attempt is made to overload an invalid (e.g., ↵jkeenan2012-01-161-17/+30
| | | | misspelled) operator. For RT #74098.
* [perl #40333] Stop overload::Overloaded from calling ->canFather Chrysostomos2012-01-091-1/+1
| | | | | | | | | | | | | | It’s possible, and too easy, for classes to define a can method to deal with AUTOLOAD, without taking overloading into account. Since AUTOLOAD is the main reason for overriding can, and since overloading does not respect autoloading, can overrides should not be expected to deal with it. Since overload.pm already has a mycan function that fits this purpose, this commit changes Overloaded to use that. The test includes an example of a class structure that the previous Overloaded implementation could not handle.
* Increase $overload::VERSION to 1.17Father Chrysostomos2012-01-051-1/+1
|