Hi Developers,

Here http://search.cpan.org/~stevan/Moose/lib/Moose/Cookbook/Recipe3.pod I
can read:
"The next attribute option is new, though: the predicate option. This option
creates a method which can be used to check whether a given slot (in this
case parent) contains a defined value. In this case it will create a method
called has_parent. Quite simple, and quite handy too."

Truly said predicate checks if value was set or not.
When I will set attribute with 'undef' actually predicate will say 'true'.
Moose version 0.40.

Please see this simple test:

#!/perl

use strict;
use warnings;

use Carp;
use Data::Dumper;

use Test::More qw(no_plan);
use Test::Exception;

package TestPredicate;
use Moose 0.40;


has 'item' => ( is => 'ro',
                isa => 'Str|Undef',
                predicate => 'has_item');

no Moose;

package main;


my $obj1 = TestPredicate->new();
ok( !$obj1->has_item, "I don't have value, because I didn't give anything");


my $obj2 = TestPredicate->new( item => undef );
ok( !$obj2->has_item, "I shouldn't have item, but I set undef");



I miss something or there is a bug ?


Thanks!
Peter

Reply via email to