How can I extend Moose's automatic pragma exports?

后端 未结 4 1829
时光说笑
时光说笑 2021-02-08 13:36

You know how Moose automatically turns on strict and warnings during import? I want to extend that behavior by turning on autodie and

4条回答
  •  孤街浪徒
    2021-02-08 14:03

    My approach solves the problem backwards.

    Why not use ToolSet to create a group of use statements that includes Moose, along with your additional pragmas?

    The code should look something like:

     # MagicMoose.pm
     package MagicMoose;
    
     use base 'ToolSet'; 
    
     ToolSet->use_pragma( qw/feature :5.10/ ); # perl 5.10
     ToolSet->use_pragma( qw/autodie/ );
    
     # define exports from other modules
     ToolSet->export(
         'Moose'          => undef,       # get the defaults
     );
    
     1; # modules must return true
    

    I haven't tested this. Frankly, I just found ToolSet a few days ago, and haven't had a chance to try it out yet. FWIW, the reviews are positive.

提交回复
热议问题