before it is returned to the caller. The C<BUILD> method provides an
opportunity to check the object state as a whole. This is a good place
to put logic that cannot be expressed as a type constraint on a single
-object.
+attribute.
In the C<Person> class, we need to check the relationship between two
attributes, C<ssn> and C<country_of_residence>. We throw an exception
=> from 'HashRef'
=> via { HTTP::Headers->new( %{$_} ) };
- subtype 'My.URI' => as class_type('HTTP::Headers');
+ subtype 'My.URI' => as class_type('URI');
coerce 'My.URI'
=> from 'Object'
Once again, we need to declare a class type for our non-Moose L<URI>
class:
- subtype 'My.URI' => as class_type('HTTP::Headers');
+ subtype 'My.URI' => as class_type('URI');
Then we define the coercion:
comparison and display code for objects.
Let's start with C<Eq>. First, note that we've replaced C<use Moose>
-with C<use Moose::Role>. We also have a new sugar function, C<required>:
+with C<use Moose::Role>. We also have a new sugar function, C<requires>:
requires 'equal_to';