Subject: | Strange interaction with Path::Class and/or overloading |
perl 5.10.0
Mouse 0.48
Path::Class 0.18
Ubuntu 9.10
If I create a class with a string attribute e.g.
has path => (is => 'rw', isa => 'Str');
- and combine getting and setting that attribute e.g.
my $path = $self->path($0);
- the setter returns undef (mouse_bad.pl) if the path is an explicitly
stringified Path::Class::File:
use Path::Class::File qw(file);
my $path = $self->path(file($0)->stringify);
Everything works as expected (mouse_good.pl) if the path is stringified
implicitly:
my $path = $self->path(file($0) . '');
I realise it could be a Path::Class issue, but I'm reporting it here to
start with because the error doesn't occur in Moose :-)
Subject: | mouse_good.pl |
#!/usr/bin/env perl
package MyClass;
use Mouse;
use Path::Class qw(file);
has path => (
is => 'rw',
isa => 'Str',
);
sub BUILD {
my $self = shift;
my $path1 = file($0) . '';
warn "path 1: $path1", $/;
$self->path(file($0) . '');
my $path2 = $self->path();
warn "path 2: $path2", $/;
my $path3 = $self->path(file($0) . '');
die 'ERROR: path not defined' unless (defined $path3);
warn "path 3: $path3", $/;
}
package main;
use feature qw(say);
my $object = MyClass->new();
say 'path: ', $object->path();
Subject: | mouse_bad.pl |
#!/usr/bin/env perl
package MyClass;
use Mouse;
use Path::Class qw(file);
has path => (
is => 'rw',
isa => 'Str',
);
sub BUILD {
my $self = shift;
my $path1 = file($0)->stringify;
warn "path 1: $path1", $/;
$self->path(file($0)->stringify);
my $path2 = $self->path();
warn "path 2: $path2", $/;
my $path3 = $self->path(file($0)->stringify);
die 'ERROR: path not defined' unless (defined $path3);
warn "path 3: $path3", $/;
}
package main;
use feature qw(say);
my $object = MyClass->new();
say 'path: ', $object->path();