Skip Menu |

This queue is for tickets about the Class-Std CPAN distribution.

Report information
The Basics
Id: 20019
Status: open
Priority: 0/
Queue: Class-Std

People
Owner: Nobody in particular
Requestors: ammon [...] rhythm.com
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Subject: Simpler validation of data values during init and "set_"
When creating a new object, there is no way to assess the validity of argument values, without having to create your own BUILD() and set_ methods: package File::Heirarchy; use Class::Std; { my %root_of :ATTR( init_arg => root ); # etc... } my $tree = eval { File::Heirarchy->new({ root => '' }) }; # Error! In this instance, I want the call to new() to fail, though Class::Std is quite happy to allow it, on account of the value being defined. Doing a custom BUILD() and set_ function "works", but it seems to go against the principle espoused in PBP to have automatic attribute initialization and verification. It also opens the door to "rewriting" that code poorly. In addition, there are also some other problems with doing additional checking in a custom BUILD() function (see bug #18747). What I'd *really* like to do is write a function that does those extra checks, and provide it as an ATTR() argument: package File::Heirarchy; use Class::Std; { my %root_of :ATTR( init_arg => root, validator => 'check_root' ); # Additional verification for root argument. sub check_root { my ($self, $root) = @_; croak "'root' must be non-empty" unless length $root; croak "'root' must be an existing directory" unless -d $root; return 1; } # etc... } This way, I get the automatic attribute initialization and verification, plus my additional checks, without having to write any extra functions. Attached is the module with the necessary changes (from v0.0.8) to implement this. I believe the changes also fix bug #18747.
Subject: Std.pm

Message body is not shown because it is too large.

Does START() address your concerns?