in reply to Re: Moose required creates empty object Can't locate object method "x" via package "Point"
in thread Moose required creates empty object Can't locate object method "x" via package "Point"
You can remove a lot unnecessary "scaffolding" from your code:
Strange things can happen when you don't put your modules into a proper lib/ dir, etc. etc. ... but i love and utilize the convenience of being able to put everything into one source file from time to time. :)#!/usr/bin/perl package Point; use Moose; has 'x' => (isa => 'Int', is => 'rw', required => 1); has 'y' => (isa => 'Int', is => 'rw', required => 1); sub clear { my $self = shift; $self->x(0); $self->y(0); } package main; use strict; use warnings; print Point->new->dump; print Point->new({})->dump; print Point->new({})->x; __END__ Attribute (x) is required at /PATH/TO/Moose/Object.pm line 24 Moose::Object::new('Point') called at foo.pl line 17
jeffa
L-LL-L--L-LL-L--L-LL-L-- -R--R-RR-R--R-RR-R--R-RR B--B--B--B--B--B--B--B-- H---H---H---H---H---H--- (the triplet paradiddle with high-hat)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Moose required creates empty object Can't locate object method "x" via package "Point"
by Anonymous Monk on May 18, 2015 at 22:24 UTC | |
by Anonymous Monk on May 18, 2015 at 22:28 UTC |