moose

Dealing with multiple-inherited constructors in Moose

懵懂的女人 提交于 2019-12-13 13:02:35
问题 Greetings, I'm learning Moose and I'm trying to write a CGI::Application subclass with Moose, which is made difficult by the fact that CGI-App is not based on Moose. In my other CGI-App subclasses, I like to have a parent class with a setup method that looks at the child class's symbol table and automatically sets up the runmodes. I figure I can use Moose's metaclass facilities to achieve the same thing in a cleaner way. So here is what I have in my parent class: use MooseX::Declare; class

Perl Moose attribute not force type checking [closed]

十年热恋 提交于 2019-12-13 09:31:34
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 8 years ago . I an using strawberry perl, Moose 2.0010 In the class: package Cat; use 5.010; use strict; use Moose; has 'name', is => 'ro', isa => 'Str', default => 'Beauty'; #has 'age', is => 'ro'; has 'diet', is => 'rw',

Perl MooseX::Declare with method attributes MooseX::MethodAttributes

帅比萌擦擦* 提交于 2019-12-13 04:56:29
问题 I am trying to use Moose, MooseX::Declare, and MooseX::MethodAttributes to be able to use class and method keywords instead of package and sub and at the same time get the methods attributes, so I need this form of packages and methods: class Moosey { method connect ($user, $pass) : Action GET {...} } If I use sub keyword it will work with attributes but of course no method signatures, If I use method keyword, it will hang the script if I use method attributes. Below is the code I am trying:

Perl Moose: Attribute only getting set when mentioned in BUILD subroutine

ⅰ亾dé卋堺 提交于 2019-12-12 17:23:42
问题 I've building a script that recursively builds the names of a directory's subdirectories/files and the names of the files in those subdirectories as objects: package Dir; use Moose; use Modern::Perl; use File; use strict; use warnings; has 'path' => (is => 'ro', isa => 'Str', required => 1); has 'name' => (is => 'ro', isa => 'Str', lazy => 1, default => sub { my $self = shift; my ($name) = $self->path =~ /\/([^\/]*)$/; return $name; } ); has 'subdirs' => (is => 'rw', isa => 'ArrayRef[Dir]' );

Parametrizing type with another type using Type::Tiny

自作多情 提交于 2019-12-12 14:24:39
问题 I want to create a type, based on the string, which will have upper length limit, and - optionally - lower length limit. I.e., parameterized type, where length range would be a parameter. What I want in my implementation: A separate type for string length range. Not using MooseX::Types::Parameterizable A sugar of parametrizing the type straight with arrayref, NOT hashref: This: isa=>Varchar[1, 15] Not this: isa=>Varchar[{min=>1, max=>15,}] That's what I have so far: File MyTypesTiny.pm

Unblessing Perl objects and constructing the TO_JSON method for convert_blessed

拜拜、爱过 提交于 2019-12-12 07:34:46
问题 In this answer I found a recommendation for a simple TO_JSON method, which is needed for serializing blessed objects to JSON. sub TO_JSON { return { %{ shift() } }; } Could anybody please explain in detail how it works? I changed it to: sub TO_JSON { my $self = shift; # the object itself – blessed ref print STDERR Dumper $self; my %h = %{ $self }; # Somehow unblesses $self. WHY??? print STDERR Dumper \%h; # same as $self, only unblessed return { %h }; # Returns a hashref that contains a hash.

Carp reporting from the wrong location with @CARP_NOT (Moose and Method Modifiers)

点点圈 提交于 2019-12-11 14:15:58
问题 This is a followup question to warnings::warnif( 'deprecated' … ) with carp?. here's a snippet of my code from Business::CyberSource on Github note: the previous answer (in the previous question), and adding of @CARP_NOT have demonstrated that warnings::warnif uses carp . I attempted to substitute carp directly, the behavior was exactly the same. our @CARP_NOT = ( __PACKAGE__, qw( Class::MOP::Method::Wrapped ) ); around BUILDARGS => sub { my $orig = shift; my $class = shift; my $args = $class

Proper way to use a Moose class attribute in a regex?

我怕爱的太早我们不能终老 提交于 2019-12-11 10:45:59
问题 I now know that the proper way to access Moose class attributes is to ALWAYS go through the accessor method that is automatically generated by Moose . See Friedo's answer to my previous question for the reasons why. However this raises a new question... How do you ensure Moose class attributes are handled correctly within regular expressions? Take the following for example: Person.pm package Person; use strict; use warnings; use Moose; has 'name' => (is => 'rw', isa => 'Str'); has 'age' =>

Moose: Array of Objects->loop through Attribute

余生长醉 提交于 2019-12-11 08:06:52
问题 I'm new to Perl Moose, and I'm trying to achieve this simple task. I have my Moose class "TestObject" defined: package TestObject; use Moose; use namespace::autoclean; has 'Identifier' => (is =>'ro',isa=>'Str'); around BUILDARGS => sub { my $orig = shift; my $class = shift; if ( @_ == 1 && ! ref $_[0] ) { return $class->$orig(Identifier => $_[0]); } else { return $class->$orig(@_); } }; __PACKAGE__->meta->make_immutable; 1; In another script I'm trying to access the attribute "Identifier"

Perl/Moose object initialization with coercion into ArrayRef

送分小仙女□ 提交于 2019-12-11 08:03:51
问题 Need make a module what accepts one or more paths , and coerce them to array of Class::Path . In the CPAN exists a module MooseX::Types::Path::Class. From it's source I discovered than the module defined subtypes Dir and File . My example module: package Web::Finder; use namespace::sweep; use Modern::Perl; use Moose; use MooseX::Types::Path::Class qw(Dir); #??? - is this correct? use Method::Signatures::Simple; use Path::Class; #should accept one or more directories as Str or as Path::Class: