Lines Matching refs:to

24       #print STDERR "Setting `$ {'package'}::\cO$_' to \\&`$sub'.\n";
214 subroutine, a reference to a subroutine, or an anonymous subroutine
218 The subroutine C<add> will be called to execute C<$a+$b> if $a
219 is a reference to an object blessed into the package C<Number>, or if $a is
221 reference to a C<Number>. It can also be called in other situations, like
223 methods refer to methods triggered by an overloaded mathematical
235 two arguments are the two arguments of the operation. However, due to
240 are reversed is vital to the subtraction method. The method can
258 information can be used to generate some optimizations. Compare
277 The routines which implement these operators are expected to actually
278 I<mutate> their arguments. So, assuming that $obj is a reference to a
294 to be assigned to the value in the left-hand-side if different from
297 This allows for the same method to be used as overloaded C<+=> and
304 B<Warning.> Due to the presence of assignment versions of operations,
318 to non-optimized version if C<not defined $_[2]> (see
323 C<',' . $obj . ','> may be both optimized to
340 C<->, C<+=>, and C<-=> can be called to automatically generate
341 increment and decrement methods. The operation C<-> can be used to
354 used to substitute for the missing operation. During C<sort>ing
355 arrays, C<cmp> is used to compare values subject to C<use overload>.
381 Note that traditionally the Perl function L<int> rounds to 0, thus for
398 probably a bug, because you're likely to get something that looks like
405 If not overloaded, the argument will be converted to a filehandle or
424 The dereference operators must be specified explicitly they will not be passed to
479 then the subroutine C<D::plus_sub> will be called to implement
487 ancestor is used, but this is accidental and subject to change.
496 C<"nomethod"> should be followed by a reference to a function of four
501 corresponding to the missing method. If several methods are tried,
502 the last one is used. Say, C<1-$a> can be equivalent to
514 assigned to C<"nomethod">, then an exception will be raised via die()--
520 The key C<"fallback"> governs what to do if a method for a particular
528 Perl tries to use a
530 then tries to calls C<"nomethod"> value; if missing, an exception
536 it silently reverts to what it would have done were there no C<use overload>
541 No autogeneration is tried. Perl tries to call
551 The value for C<"="> is a reference to a function with three
557 to a reference that shares its object with some other reference, such
564 and $a is assigned a reference to this new object. This operation is
609 TRUE or undefined, Perl tries to autogenerate a substitute method for
665 can be expressed in terms of an assignment to the dereferenced value, if this
682 When you chop() a mathemagical object it is promoted to a string and its
688 Since all C<use> directives are executed at compile-time, the only way to
689 change overloading during run-time is to
711 Returns true if C<arg> is subject to overloading of some operations.
715 Returns C<undef> or a reference to the method that implements C<op>.
722 to hook into this process via overload::constant() and overload::remove_constant()
732 to overload integer constants,
736 to overload floating point constants,
740 to overload octal and hexadecimal constants,
744 to overload C<q>-quoted strings, constant pieces of C<qq>- and C<qx>-quoted
749 to overload constant pieces of regular expressions.
753 The corresponding values are references to functions which take three arguments:
760 constant is going to be interpreted by Perl. The third argument is undefined
771 Note that it is probably meaningless to call the functions overload::constant()
787 What follows is subject to change RSN.
794 want to change overloading structure dynamically, you'll need an
795 additional (fake) C<bless>ing to update the table.
801 magic. However, the magic which implements overloading is applied to
805 If an object belongs to a package using overload, it carries a special
811 measurable performance penalties. A considerable effort was made to
813 arguments in question do not belong to packages using overload. When
825 carried out before any operation that can imply an assignment to the
826 object $a (or $b) refers to, like C<$a++>. You can override this
829 It is expected that arguments to methods that are not explicitly supposed
830 to be changed are constant (but this is not enforced).
835 If it I<looks> counter intuitive to you, you are subject to a metaphor
840 I< object is a reference to blessed data>
848 objects. Perl-think implies that $a becomes a reference to whatever
850 $a is changed to become the value of the object $b, preserving the fact
860 to enable this metaphor while preserving the Perlian way as far as
861 possible. Since it is not possible to freely mix two contradicting
862 metaphors, overloading allows the arithmetic way to write things I<as
866 If some mutator methods are directly applied to the overloaded values,
867 one may need to I<explicitly unlink> other values which references the
872 $b = $a; # $b is "linked" to $a
880 $b = $a; # $b is "linked" to $a
888 preserve "objectness" of $a. But Perl I<has> a way to make assignments
889 to an object do whatever you want. It is just not the overload, but
899 Please add examples to what follows!
927 Suppose you want to create an object which is accessible as both an
928 array reference and a hash reference, similar to the
931 allowing index 0 to be treated as a normal element.
977 This allows us not to worry about a possibility of a reference loop,
978 which would lead to a memory leak.
980 Both these problems can be cured. Say, if we want to overload hash
981 dereference on a reference to an object which is I<implemented> as a
982 hash itself, the only problem one has to circumvent is how to access
983 this I<actual> hash (as opposed to the I<virtual> hash exhibited by the
1032 Now if $baz is overloaded like this, then C<$baz> is a reference to a
1033 reference to the intermediate array, which keeps a reference to an
1035 hash is a reference to a reference to the actual array, so
1046 references to a reference to an array, thus references to a I<scalar>.
1092 there is no simple way to I<use> this value. In fact this value may
1096 If one attempts to print this value, then the overloaded operator
1099 again of type C<symbolic>, which will lead to an infinite loop.
1101 Add a pretty-printer method to the module F<symbolic.pm>:
1116 The method C<pretty> is doing object-to-string conversion, so it
1117 is natural to overload the operator C<""> using this method. However,
1118 inside such a method it is not necessary to pretty-print the
1123 look for an overloaded operator C<"">. Thus it is enough to use
1133 Now one can change the last line of the script to
1148 Indeed, to terminate the cycle, the $cnt should become false.
1151 of type C<symbolic> is true. To overcome this, we need a way to
1152 compare an object to 0. In fact, it is easier to write a numeric
1188 or die "Do not know how to ($meth) in symbolic";
1226 the tables of operations, and change the code which fills %subr to
1241 Due to L<Calling Conventions for Mutators>, we do not need anything
1242 special to make C<+=> and friends work, except filling C<+=> entry of
1244 way to know that the implementation of C<'+='> does not mutate
1247 To implement a copy constructor, add C<< '=' => \&cpy >> to C<use overload>
1256 To make C<++> and C<--> work, we need to implement actual mutators,
1257 either directly, or in C<nomethod>. We continue to do things inside
1294 to an existing overloaded operator C<"">. Overloaded arithmetic
1295 operators I<do not> fall back to numeric conversion if C<fallback> is
1297 would convert C<['+', $a, $b]> to C<$a + $b>, which would just rebuild
1301 num(), note how easy it was to write the symbolic calculator. This
1302 simplicity is due to an appropriate choice of defaults. One extra
1303 note: due to the explicit recursion num() is more fragile than sym():
1304 we need to explicitly check for the type of $a and $b. If components
1305 $a and $b happen to be of some related type, this may lead to problems.
1321 to the package C<symbolic>. After this change one can do
1334 To hide the rough edges under the hood, provide a tie()d interface to the
1366 shows that the numeric value of $c follows changes to the values of $a
1381 is shown by debugger. The method C<()> corresponds to the C<fallback>
1392 (W) The call to overload::constant contained an odd number of arguments.
1397 (W) You tried to overload a constant type the overload package is unaware of.
1402 to be a code reference. Either an anonymous subroutine, or a reference
1403 to a subroutine.
1423 tie()d value does not change, a simple workaround is to access the value
1427 B<Needed:> a way to fix this without a speed penalty.