Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Your output has two different classes in it:

Zep is              OT::Zeppelin::AddVendorKey 
stringifies as      OT::Zeppelin::AddVendorKey….
_stringify returns  OT::DB::Result::Upload...

So it looks like the line $this->row->ID can return two different objects.

The 'use overload' docs say:

The subroutines for '""' , '0+' , and 'bool' can return any arbitrary Perl *value*. If the corresponding operation for this *value* is overloaded too, the operation will be called again with this *value*.

As a special case if the overload returns the object itself then it will be used directly. An overloaded conversion returning the object is probably a bug, because you're likely to get something that looks like YourPackage=HASH(0x8172b34) .

Based on the order of the output, I would say that $this->row->ID is returning $this in some cases, and in other cases it is returning an object of the class OT::DB::Result::Upload, and that class has also overloaded '""'.

Here is a simple example of that:

use strict; use warnings; use 5.012; ############## { package Point; use Moose; # automatically turns on strict and warnings has 'x' => (is => 'rw', isa => 'Int'); has 'y' => (is => 'rw', isa => 'Int'); use overload '""' => \&_stringify; sub _stringify { state $count; my ($rhs, $_lhs, $swap) = @_; $count++; if ($count < 2) { return $rhs; } else { return D->new; } } } ################ { package Point3D; use Moose; extends 'Point'; has 'z' => (is => 'rw', isa => 'Int'); } ############### { package D; use Moose; use overload '""' => sub { my $class = ref shift; return "$class|hello" }; } ############### my $p3d = Point3D->new(x=>10, y=>20); say "$p3d"; say $p3d->_stringify; --output:-- Point3D=HASH(0x100bc5078) D|hello

In reply to Re: Moose stringification overloading isn't working by Anonymous Monk
in thread Moose stringification overloading isn't working by dd-b

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!
  • 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, 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, 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.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (7)
    As of 2015-07-08 04:54 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









      Results (94 votes), past polls