--- trunk/lib/App/RoomReservation/Reservation.pm 2009/06/29 12:11:14 1104 +++ trunk/lib/App/RoomReservation/Reservation.pm 2009/06/30 13:24:03 1121 @@ -1,6 +1,14 @@ package App::RoomReservation::Reservation; use Moose; +use Moose::Util::TypeConstraints; +use Regexp::Common qw[Email::Address]; + +subtype 'Email', + as 'Str', + where { /^$RE{Email}{Address}$/ }, + message { "$_ is not valid e-mail" }; + extends 'App::RoomReservation'; use lib 'lib'; @@ -56,33 +64,43 @@ has email => ( is => 'rw', - isa => 'Str', + isa => 'Email', required => 1, ); has email_verify => ( is => 'rw', - isa => 'Str', + isa => 'Email', required => 1, ); has _confirmed => ( is => 'rw', isa => 'Bool', - required => 1, +# required => 1, default => sub { 0 }, ); +has _seat_number => ( + is => 'rw', + isa => 'Int', +); + sub BUILD { my $self = shift; die "e-mail not verified\n" unless $self->email eq $self->email_verify; + my $sth = $self->dbh->prepare(qq{ + select count(*) from reservation where email = ? + }); + $sth->execute( $self->email ); + my ($registred) = $sth->fetchrow_array; + die "e-mail address ", $self->email, " allready registred\n" if $registred; } my @cols = Frey::PPI->new( class => __PACKAGE__ )->attribute_order; warn "# cols = ",join(',', @cols), $/; sub token { - my ( $self ) = @_; my $self = shift; my $sth = $self->dbh->prepare(qq{ select md5( id || email ) from reservation where email = ?