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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T21:02:00+00:00 2026-06-13T21:02:00+00:00

I get a compile time error (Moose complains about modifying an immutable instance) running

  • 0

I get a compile time error (Moose complains about modifying an immutable instance)
running ‘perl -c’ on a package but code using the package runs error-free.
Example Code:

File Pa_1.pm (immutable Moose class using MooseX::Aliases and package Pa_2.pm):

package Pa_1;

use Pa_2;

use Moose;

# uncommenting either this line ...
use MooseX::Aliases;

# ... or this line to make 'perl -c' work
__PACKAGE__->meta->make_immutable;

1;

File Pa_2.pm (just using Pa_1.pm which uses Pa_2.pm):

package Pa_2;

use Pa_1;
1;

File run_pa_1.pl :

#!/usr/bin/env perl

use Pa_1;

my $pa1 = Pa_1->new();
print "Done !\n";

Executing run_pa_1.pl works, but ‘perl -c Pa_1.pm’ gives

The 'add_method' method cannot be called on an immutable instance at /home/pecho/perl5/perlbrew/perls/perl-5.16.1/lib/site_perl/5.16.1/x86_64-linux/Class/MOP/Class/Immutable/Trait.pm line 32.
        Class::MOP::Class::Immutable::Trait::_immutable_cannot_call('add_method') called at /home/pecho/perl5/perlbrew/perls/perl-5.16.1/lib/site_perl/5.16.1/x86_64-linux/Class/MOP/Class/Immutable/Trait.pm line 47
        Class::MOP::Class:::around('CODE(0xc10158)', 'Class::MOP::Class::Immutable::Moose::Meta::Class::__ANON__::S...', 'DESTROY', 'Moose::Meta::Method::Destructor=HASH(0x14af4f8)') called at /home/pecho/perl5/perlbrew/perls/perl-5.16.1/lib/site_perl/5.16.1/x86_64-linux/Class/MOP/Method/Wrapped.pm line 162
        Class::MOP::Method::Wrapped::__ANON__('Class::MOP::Class::Immutable::Moose::Meta::Class::__ANON__::S...', 'DESTROY', 'Moose::Meta::Method::Destructor=HASH(0x14af4f8)') called at /home/pecho/perl5/perlbrew/perls/perl-5.16.1/lib/site_perl/5.16.1/x86_64-linux/Class/MOP/Method/Wrapped.pm line 91
        Class::MOP::Class::Immutable::Moose::Meta::Class::__ANON__::SERIAL::1::add_method('Class::MOP::Class::Immutable::Moose::Meta::Class::__ANON__::S...', 'DESTROY', 'Moose::Meta::Method::Destructor=HASH(0x14af4f8)') called at /home/pecho/perl5/perlbrew/perls/perl-5.16.1/lib/site_perl/5.16.1/x86_64-linux/Class/MOP/Mixin/HasMethods.pm line 181
        Class::MOP::Mixin::HasMethods::_restore_metamethods_from('Class::MOP::Class::Immutable::Moose::Meta::Class::__ANON__::S...', 'Class::MOP::Class::Immutable::Moose::Meta::Class::__ANON__::S...') called at /home/pecho/perl5/perlbrew/perls/perl-5.16.1/lib/site_perl/5.16.1/x86_64-linux/Class/MOP/Class.pm line 405
        Class::MOP::Class::_restore_metaobjects_from('Class::MOP::Class::Immutable::Moose::Meta::Class::__ANON__::S...', 'Class::MOP::Class::Immutable::Moose::Meta::Class::__ANON__::S...') called at /home/pecho/perl5/perlbrew/perls/perl-5.16.1/lib/site_perl/5.16.1/x86_64-linux/Moose/Meta/Class.pm line 728
        Moose::Meta::Class::_restore_metaobjects_from('Class::MOP::Class::Immutable::Moose::Meta::Class::__ANON__::S...', 'Class::MOP::Class::Immutable::Moose::Meta::Class::__ANON__::S...') called at /home/pecho/perl5/perlbrew/perls/perl-5.16.1/lib/site_perl/5.16.1/x86_64-linux/Class/MOP/Class.pm line 65
        Class::MOP::Class::reinitialize('Class::MOP::Class::Immutable::Moose::Meta::Class::__ANON__::S...', 'Class::MOP::Class::Immutable::Moose::Meta::Class::__ANON__::S...', 'error_class', 'Moose::Error::Default', 'wrapped_method_metaclass', 'Class::MOP::Method::Wrapped', 'instance_metaclass', 'Moose::Meta::Instance', 'method_metaclass', ...) called at /home/pecho/perl5/perlbrew/perls/perl-5.16.1/lib/site_perl/5.16.1/x86_64-linux/Moose/Meta/Class.pm line 188            Moose::Meta::Class::reinitialize('Class::MOP::Class::Immutable::Moose::Meta::Class::__ANON__::S...', 'Class::MOP::Class::Immutable::Moose::Meta::Class::__ANON__::S...', 'attribute_metaclass', 'Moose::Meta::Class::__ANON__::SERIAL::2') called at /home/pecho/perl5/perlbrew/perls/perl-5.16.1/lib/site_perl/5.16.1/x86_64-linux/Moose/Util/MetaRole.pm line 99            Moose::Util::MetaRole::_make_new_metaclass('Class::MOP::Class::Immutable::Moose::Meta::Class::__ANON__::S...', 'HASH(0x144f868)', 'class') called at /home/pecho/perl5/perlbrew/perls/perl-5.16.1/lib/site_perl/5.16.1/x86_64-linux/Moose/Util/MetaRole.pm line 28            Moose::Util::MetaRole::apply_metaroles('for', 'Class::MOP::Class::Immutable::Moose::Meta::Class::__ANON__::S...', 'class_metaroles', 'HASH(0x144f868)', 'role_metaroles', 'HASH(0x144f838)') called at /home/pecho/perl5/perlbrew/perls/perl-5.16.1/lib/site_perl/5.16.1/x86_64-linux/Moose/Exporter.pm line 543
        Moose::Exporter::_apply_metaroles('Pa_1', 'ARRAY(0x93c630)', 'CODE(0xddccc8)') called at /home/pecho/perl5/perlbrew/perls/perl-5.16.1/lib/site_perl/5.16.1/x86_64-linux/Moose/Exporter.pm line 460
        Moose::Exporter::__ANON__('MooseX::Aliases') called at Pa_1.pm line 6
        Pa_1::BEGIN() called at Pa_1.pm line 6
        eval {...} called at Pa_1.pm line 6
BEGIN failed--compilation aborted at Pa_1.pm line 6.

I am a little confused because an error is emitted starting perl on Pa_2.pm with compile switch but run time seems to be ok.

  • In debugger and doing ‘use Pa_2’ there is no error too.
  • Executing ‘perl -c run_pa_1.pl’ no error too.
  • Not using MooseX::Aliases or not
    making Pa_1.pm immutable let ‘perl -c Pa_1.pm’ compile without error.

Is there a bug in the code, in MooseX::Aliases or is it something internal to Moose ?

Versions used : perl 5.16.1; Moose 2.0604; MooseX::Aliases 0.10;

  • 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-06-13T21:02:02+00:00Added an answer on June 13, 2026 at 9:02 pm

    Never execute a module directly. You end up compiling and executing it twice.

    Similarly, never compile a module directly. You end up compiling it twice.

    perl -c Pa_1.pm
    

    should

    perl -c -e'use Pa_1;'
    

    perl -c Pa_1.pm executes the following (ignoring require and import that do nothing):

    package Pa_1;
    require Pa_2;
    
    package Pa_2;
    require Pa_1;
    
    package Pa_1;
    require Moose;
    import Moose;
    require MooseX::Aliases;
    import MooseX::Aliases;
    __PACKAGE__->meta->make_immutable;
    1;
    
    package Pa_2;
    1;
    
    package Pa_1;
    import Moose;
    import MooseX::Aliases;
    

    perl -c -e'use Pa_1; executes the following (ignoring require and import that do nothing):

    package Pa_1;
    require Pa_2;
    
    package Pa_2;
    1;
    
    package Pa_1;
    require Moose;
    import Moose;
    require MooseX::Aliases;
    import MooseX::Aliases;
    __PACKAGE__->meta->make_immutable;
    1;
    

    Notice how you end up doing

    import Moose;
    import MooseX::Aliases;
    

    after doing

    __PACKAGE__->meta->make_immutable;
    

    when you do it wrong?

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

Sidebar

Related Questions

In the following code, I get a compile time error: ByRef Argument type mismatch.
In the following code, I get a compile time error because i is treated
For the attached code, I get the following compile time error : exception during
For the following code I get a compile time error, * 'int' is not
Why do I get a compile time error on this piece of code? public
We get compile time error when integer is divided by zero whereas in case
I get a compile time error on countList method. public static void countList( List<?
I get a compile error, which I'm slightly confused about. This is on VS2003.
Just wondering why I get compile time error : Attribute 'DisplayColumn' is not valid
In the following I get a compile time error that says Use of unassigned

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.