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 3322800
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:13:33+00:00 2026-05-17T23:13:33+00:00

I try to use Moose. It’s great, when it works. However, I have found

  • 0

I try to use Moose. It’s great, when it works.

However, I have found something that looks like a bug (but I will ask here before committing it).

When I run this code

package Experiment;

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

subtype 'K'
    => as 'Str';

coerce 'K'
    => from 'Str'
    => via {
        s/^([^_]*).*$/$1/;
    };

has 'k' => (
    is => 'ro',
    isa => 'K',
    coerce => 1
);

1;
package main;

my $exp = new Experiment(k=>"abcd_efgh");
print $exp->k."\n";

On one computer with perl 5.010, it correctly shows abcd. When I run it on another computer with 5.8.8 (where the script, unfortunately, has to work too), I see incorrect abcd_efgh; and the coercing subroutine never seem to actually run (if I add print or die there, for example, nothing happens on the 5.8.8 machine).

(It is really simplified, but it is an actual real life case – I need to coerce K from strings, that always have rubbish after underscore)

Do you think it is a Moose bug?

  • 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-17T23:13:34+00:00Added an answer on May 17, 2026 at 11:13 pm

    If you are really running perl 5.8.0, it’s not a bug, because Moose requires a minimum version of perl 5.8.3. Sorry.

    Are you really sure you can’t upgrade? 5.8.0 is really really old, and moving to 5.8.8 (which itself is quite old, but is still run in a lot of enterprise environments) will buy you lots of bug fixes.

    But (thanks doy for noticing this), your coercion will never run anyway, because the existing type constraint ‘K’ will pass. You need to add a where clause to the subtype definition, in order to trigger the coercion:

    subtype 'K'
        => as 'Str'
        => where { $_ !~ /_/ };
    
    coerce 'K'
        => from 'Str'
        => via {
            m/^([^_]*).*$/; $1;
            # this is an alternate method:
            # (split('_', $_, 2))[0];
        };
    

    (Note that the substitution operator returns the number of substitutions made; I’ve proposed two alternate rewrites above.)

    Lastly, the code as you have written in your question prints “abcd_efgh” on a fully-operational system, so are you sure you are running the same code on both boxes?

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

Sidebar

Related Questions

When I try to use curl or file_get_contents to read something like http://example.com/python/json/ from
I try to use a PageableListView with PagingNavigation. From the examples that looks quite
I try to use templatetags in django but I have trouble. I defined enumhelper.py
I frequently use Moose to make sure my data have suitable default values, like
i try to use SendMessage with EM_FINDWORDBREAK i have got the position of mouse
I am thinking to try writing an app that can use android phone to
EDIT: OH!!!!! it works!!! It seems that at one point it was fixed However
I try to use custom icons for the markers on my map. It works
When I try to use an ssh command in a shell script, the command
When I try to use the code below I get a duplicate variable error

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.