Erm, no. I'm just talking about making the method called by the normal overload call examine the instance in question to decide what to do. I don't see how that would change anything about the automagically generated boolification or numification logic.

#!/usr/bin/perl use strict; use warnings; package Ovl; use overload '""' => \&mystring; sub new { my $ret = bless {}, shift(); $ret->{_name} = shift; $ret->{_str_code} = \&_str_default; return $ret; } sub _str_default { my $self = shift; "!" . $self->{_name} . "!" } sub mystring { my $self = shift; my $str_code = $self->{_str_code} || \&_str_default; $self->$str_code( @_ ); } package main; my $o = Ovl->new( "default" ); print "$o\n"; my $o_undef = Ovl->new( undef ); $o_undef->{_str_code} = sub { "I R UNDEFINED" }; print "$o_undef\n" if $o_undef; my $o_numeric = Ovl->new( 15 ); $o_numeric->{_str_code} = sub { sprintf( "%0.5f", shift->{_name} ) }; print "$o_numeric\n" if int( $o_numeric ) == 15; exit 0; __END__

Update: AAAAAHHH. Just reread the OP's code and I see what you're getting at. In order to implement arbitrary overload operations on instances (i.e. what operations are overloaded on the instance, not just what each operation does on each instance) you would need to have defined handlers for all possible operations for the class itself and then yes you would need duplicate dispatching logic. I was thinking of the case where each instance shared the same set of overloaded operations, whereas his allows instance level selection of what's overloaded. I just glanced over his code and missed that he was trying to get different sets of overload behavior per instance. Bah, it's quitting time on Friday.

The cake is a lie.
The cake is a lie.
The cake is a lie.


In reply to Re^3: Overloading different instances differently. by Fletch
in thread Overloading different instances differently. by kyle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.