Friday, 15 August 2014

perl - Is there any way I can use Moose::Exporter from within a Moose object? -


I'm looking for a way to set some helpful methods from within a parent class instead of a standalone utility class. If this is possible, then there will be a more transparent method of adding the shape of the module to the module, as it does not explicitly require any supporting modules (as extends through the declaration of everything Will come).

Based on this, it is almost exactly what I am doing:

  package guardian; Use mousse; Moose :: Exporter- gt; Setup_import_methods (with_meta = & gt; [has_rw '], as_is = & gt; [' talk '], also = & gt;' mousse ',); Sub has_rw {my ($ meta, $ name,% option) = @_; $ Meta- & gt; Add_person ($ name, is => 'rw',% option,); } # Later ... package child; Use mousse; Expansion of 'parent'; 'Name' is; Has_rw 'size'; Cheese;  

Although this does not work:

  perl-i-mm-hill-weight '$ obj = hair-> New (size => 1); Printed $ obj- & gt; The size ' 
 string found that the operator who has the "has_rw' size '' on the Child.pm line 10 (Do you need the prerequisite of HDRC?) Syntax error Child PM The "BayerWorld" thing is not allowed near the line 10, "HdRR size", while "public PM line" requires "strict SOS" in use. BEGIN Failure - compilation was aborted. 
< P> PS I export magic to role (with roll < / Code> instead of growing parent; ), but the same errors occur.

This is not supported, and this is a good reason why a class or role is not similar to the same kind of sugar, and at different levels, different things should be different. If your problem is using the "Moose + A Custom Shoe Package", then you can resolve that your custom Chinese package With Iryat mousse, steals your Example:

  using package MySugar; strict use; Mujh :: exporter; Moose :: Exporter- gt; Setup_import_methods (with_meta = & gt; [has_rw '], as_is = & gt; [' talk '], also = & gt;' mousse ',); Sub has_rw {my ($ meta, $ name,% option) = @_; $ Meta- & gt; Add_person ($ name, is => 'rw',% option,); }  

Then you just say:

  package MyApp; Use MySage; # Moose + has_rw everything from import and extends talk (parent); Has_rw 'name'; 'Size' is; Cheese;  

How does MooseX :: POE work , as well as many other packages I will debate for anyone having extensible As you are suggesting here because there is not a bundle of class Chinese works, and both should never be confused.

Update: To bring both of them in a clean way, parents have to work again as a role that applies to the Moose :: object.

  Package Measureer :: Methods; Use 5.10.0; Use Moose: Role;  

Then we just change the music :: Exporter to call in MySugar

  Moose :: Exporter- & Gt; Setup_import_methods (apply_base_class_roles = & gt; 'Parents :: methods', with _meta = & gt; ['has_rw'], as_is = & gt; ['talk'], also => ​​'mousse');  

Now you can just say

  package MyApp; Use MySage; Has_rw 'name'; 'Size' is; Cheese; Package head; MyApp-> New- & gt; Something_special; #print sparkles  

I believe the final details you wanted.


No comments:

Post a Comment