On Tue, Nov 3, 2009 at 10:01 AM, Ovid <publiustemp-catal...@yahoo.com> wrote:
> When parsing documents, if my code finds more than one title in a document, 
> it's an error because we don't know which title is needed.  The user should 
> be able to override this in the constructor and provide their own title (this 
> is actually true for several attributes):

So the mechanism you're looking for is (1) if the title is not set in
the constructor and (2) if it has already been set in runtime then (3)
die. This can be accomplished easy enough, with around and a
predicate, and it will ensure consistency throughout the program and
anything that subclasses it.

has 'attribute' => ( isa => 'Str', is => 'ro', predicate => 'has_attribute' );

around 'attribute' => sub {
my ($next, $this, $key) = @_;
$self->has_attribute ? die 'exception' : $this->$next($key);
};

-- 
Evan Carroll
System Lord of the Internets

Reply via email to