Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6667199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:54:29+00:00 2026-05-26T02:54:29+00:00

Ok just to sanity check overload doesnt seem to be working for me. I

  • 0

Ok just to sanity check overload doesnt seem to be working for me. I don’t know if it’s the version of perl I have, or the version of overload.pm, or something wrong with how I’ve implemented it, but this code doesnt work for me.

perl version

This is perl, v5.10.1 (*) built for x86_64-linux-gnu-thread-multi

overload version

perl -Moverload -e 'print "$overload::VERSION\n";'
1.07

Token.pm

package Token;
use namespace::autoclean;
use Data::Dumper;


use Moose;
use Moose::Util::TypeConstraints; 

use overload '+' => \&_overload_add, fallback => 1;

  has 'secretvalue' => ( is => 'rw', isa => 'Int');  

  sub _overload_add{
    my ( $one, $two ) = @_;   
    my $value = $one->secretvalue() + $two->secretvalue();
    return ($value);
  }

main

use strict;
use warnings;
use Token;
my $t = Token->new( secretvalue => 17, key => 'x' );
my $t2 = Token->new( secretvalue => 12, key => 'y' );

my $x = $t + $t2;

print $x;

prints

 $VAR1 = 12900840;

The worst part is that I’m not getting any kind of warning or errors in the log.

UPDATE

Thanks to Freido for finding the problem. I’ve updated the question just in case anyone else stumbles on this.

Does the Perl/Moose community generally not use overload?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T02:54:29+00:00Added an answer on May 26, 2026 at 2:54 am

    namespace::autoclean is futzing with the magic that overload adds to handle your operator. The following works as you would expect:

    package Token;
    
    use Moose;
    use Moose::Util::TypeConstraints;
    
    use overload '+' => '_overload_add';
    
    has 'secretvalue' => ( is => 'rw', isa => 'Int');
    
    sub _overload_add{
        my ( $one, $two ) = @_;
        my $value = $one->secretvalue() + $two->secretvalue();
        return ($value);
    }
    
    1;
    

    A casual glance does not reveal anything in the namespace::autoclean docs that addresses this, so I guess it’s an unanticipated feature. Some searching reveals that a bug has been reported.

    I guess it comes down the special symbols that overload adds to your package. Overloading + adds the symbol table entries (), (+, and OVERLOAD. I’m guessing some or all of these are vacuumed up by namespace::autoclean, thus undoing your overloading.

    If you’re feeling adventurous, here’s a patch for namespace::autoclean that filters out overload symbols.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just a quick sanity check here! If I have a static method in an
This is just a sanity check, but I've done several test cases before you
I just need a sanity check here... DEMO Basically, I can't figure out how
I was just testing a small script in Prolog to sanity check the MySQL
just a sanity check please: in VB.NET: dim myarray(5) as integer gives six elements
I have debugged this legacy code, and would like a sanity check on it.
I have a rather large csv file (17GB) which I'm trying to sanity check.
Just to keep my sanity, I'm telling Spring to barf on circular references: _context
Just checking my JS and I have an error, but I cannot see where.
Just a knowledge question which I would like to ask: For example, I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.