Subject: | failure to "extends" together wwith MX::Attr::ENV |
Merry (soon) X-Mas.
I am trying to "extends" a Base module (which would contain basic
attributes)
When my extension uses MX::Attr::ENV the environment has no effect
(When not extending, it all works fine)
cmdline.pl
1..8
# Versions:
# MooseX::Attribute::ENV::VERSION=0.01
# perl is v5.12.2
ok 1 - e0 default
ok 2 - e1 assigned
ok 3 - f0 default
ok 4 - f1 assigned
ok 5 - e2 envir
ok 6 - e3 assigned
not ok 7 - f2 envir
# Failed test 'f2 envir'
# at t/cmdline.pl line 70.
# got: 'B'
# expected: 'F'
ok 8 - f3 assigned
# Looks like you failed 1 test of 8.
Regards Poul
Subject: | cmdline.pl |
#!/usr/bin/env perl
package Base;
use Moose;
has foo =>
(
is => 'rw',
isa => 'Str',
default => 'A',
);
# ######
package EnvironmentFAIL;
use Moose;
use MooseX::Attribute::ENV;
extends 'Base';
has '+foo' =>
(
default => 'B',
traits => [ 'ENV' ],
env_key => 'FOO',
);
# ######
package EnvironmentOK;
use Moose;
use MooseX::Attribute::ENV;
has 'foo' =>
(
is => 'rw',
isa => 'Str',
default => 'C',
traits => [ 'ENV' ],
env_key => 'FOO',
);
# ######
package main;
use Test::More tests => 8;
note('Versions:');
note( ' MooseX::Attribute::ENV::VERSION=',MooseX::Attribute::ENV->VERSION() );
note( sprintf(" perl is v%vd\n", $^V ) );
delete $ENV{FOO};
my $e0 = EnvironmentOK->new( );
my $e1 = EnvironmentOK->new( foo => "X" );
my $f0 = EnvironmentFAIL->new( );
my $f1 = EnvironmentFAIL->new( foo => "X" );
is( $e0->foo(), "C", "e0 default" );
is( $e1->foo(), "X", "e1 assigned" );
is( $f0->foo(), "B", "f0 default" );
is( $f1->foo(), "X", "f1 assigned" );
$ENV{FOO} = 'F';
my $e2 = EnvironmentOK->new( );
my $e3 = EnvironmentOK->new( foo => "X" );
my $f2 = EnvironmentFAIL->new( );
my $f3 = EnvironmentFAIL->new( foo => "X" );
is( $e2->foo(), "F", "e2 envir" );
is( $e3->foo(), "X", "e3 assigned" );
is( $f2->foo(), "F", "f2 envir" );
is( $f3->foo(), "X", "f3 assigned" );