6 Moose::Cookbook::Recipe4
16 use Regexp::Common 'zip';
18 my $STATES = Locale::US->new;
23 (exists $STATES->{code2state}{uc($_)} || exists $STATES->{state2code}{uc($_)})
29 /^$RE{zip}{US}{-extended => 'allow'}$/
32 has 'street' => (is => 'rw', isa => 'Str');
33 has 'city' => (is => 'rw', isa => 'Str');
34 has 'state' => (is => 'rw', isa => 'USState');
35 has 'zip_code' => (is => 'rw', isa => 'USZipCode');
42 has 'name' => (is => 'rw', isa => 'Str', required => 1);
43 has 'address' => (is => 'rw', isa => 'Address');
44 has 'employees' => (is => 'rw', isa => subtype ArrayRef => where {
45 ($_->isa('Employee') || return) for @$_; 1
49 my ($self, $params) = @_;
50 if ($params->{employees}) {
51 foreach my $employee (@{$params->{employees}}) {
52 $employee->company($self);
57 sub get_employee_count { scalar @{(shift)->employees} }
64 has 'first_name' => (is => 'rw', isa => 'Str', required => 1);
65 has 'last_name' => (is => 'rw', isa => 'Str', required => 1);
66 has 'middle_initial' => (is => 'rw', isa => 'Str', predicate => 'has_middle_initial');
67 has 'address' => (is => 'rw', isa => 'Address');
71 return $self->first_name .
72 ($self->has_middle_initial ? ' ' . $self->middle_initial . '. ' : ' ') .
83 has 'title' => (is => 'rw', isa => 'Str', required => 1);
84 has 'company' => (is => 'rw', isa => 'Company', weak_ref => 1);
86 override 'full_name' => sub {
88 super() . ', ' . $self->title
95 Stevan Little E<lt>stevan@iinteractive.comE<gt>
97 =head1 COPYRIGHT AND LICENSE
99 Copyright 2006 by Infinity Interactive, Inc.
101 L<http://www.iinteractive.com>
103 This library is free software; you can redistribute it and/or modify
104 it under the same terms as Perl itself.