/[Frey]/trunk/lib/App/RoomReservation/Reservation.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/App/RoomReservation/Reservation.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1095 by dpavlin, Sun Jun 28 18:51:49 2009 UTC revision 1155 by dpavlin, Thu Jul 2 10:12:54 2009 UTC
# Line 1  Line 1 
1  package App::RoomReservation::Reservation;  package App::RoomReservation::Reservation;
2  use Moose;  use Moose;
3    
4  extends 'Frey';  use Moose::Util::TypeConstraints;
5  with 'Frey::Web';  use Regexp::Common qw[Email::Address];
6    
7    subtype 'Email',
8            as 'Str',
9            where { /^$RE{Email}{Address}$/ },
10            message { "$_ is not valid e-mail" };
11    
12    extends 'App::RoomReservation';
13    
14    with 'App::RoomReservation::Email', 'App::RoomReservation::Messages';
15    
 use DBI;  
16  use lib 'lib';  use lib 'lib';
17  use Frey::PPI;  use Frey::PPI;
18    
# Line 58  has mobitel => ( Line 66  has mobitel => (
66    
67  has email => (  has email => (
68          is => 'rw',          is => 'rw',
69          isa => 'Str',          isa => 'Email',
70          required => 1,          required => 1,
71  );  );
72    
73  has email_verify => (  has email_verify => (
74          is => 'rw',          is => 'rw',
75          isa => 'Str',          isa => 'Email',
76          required => 1,          required => 1,
77  );  );
78    
79  has _confirmed => (  has _confirmed => (
80          is => 'rw',          is => 'rw',
81          isa => 'Bool',          isa => 'Bool',
82          required => 1,  #       required => 1,
83          default => sub { 0 },          default => sub { 0 },
84  );  );
85    
86  sub dsn { 'DBI:Pg:dbname=room-reservation' }  has _seat_number => (
87            is => 'rw',
88            isa => 'Int',
89    );
90    
91    has _canceled => (
92            is => 'rw',
93            isa => 'Bool',
94            default => sub { 0 },
95    );
96    
97    sub BUILD {
98            my $self = shift;
99            my $email = $self->email;
100            die "e-mail not verified\n" unless $email eq $self->email_verify;
101            my $sth = $self->dbh->prepare(qq{
102                    select count(*) from reservation where email = ?
103            });
104            $sth->execute( $email );
105            my ($registred) = $sth->fetchrow_array;
106            if ( $registred ) {
107                    die qq|
108                            <big>e-mail address $email allready registred</big>
109                    | . $self->seat_confirmation_message( email => $email )
110                    ;
111            }
112    }
113    
114  my @cols = Frey::PPI->new( class => __PACKAGE__ )->attribute_order;  my @cols = Frey::PPI->new( class => __PACKAGE__ )->attribute_order;
115  warn "# cols = ",join(',', @cols), $/;  warn "# cols = ",join(',', @cols), $/;
# Line 83  warn "# cols = ",join(',', @cols), $/; Line 117  warn "# cols = ",join(',', @cols), $/;
117  sub create_as_markup {  sub create_as_markup {
118          my ($self) = @_;          my ($self) = @_;
119    
         my $dbh = DBI->connect( $self->dsn, '', '', { RaiseError => 1 } ) || die $DBI::errstr;  
         $dbh->do( qq{ set client_encoding='utf-8' } ) if $self->dsn =~ m{pg}i;  
   
120          my @vals;          my @vals;
121          my @p;          my @p;
122    
# Line 106  sub create_as_markup { Line 137  sub create_as_markup {
137    
138          warn "sql: $sql\n";          warn "sql: $sql\n";
139    
140          my $sth = $dbh->prepare( $sql );          my $sth = $self->dbh->prepare( $sql );
141          $sth->execute( @vals );          $sth->execute( @vals );
142    
143          $sth->rows;          return $self->seat_confirmation_message( email => $self->email );
144    
145  }  }
146    
147    __PACKAGE__->meta->make_immutable;
148    no Moose;
149    no Moose::Util::TypeConstraints;
150    
151  1;  1;

Legend:
Removed from v.1095  
changed lines
  Added in v.1155

  ViewVC Help
Powered by ViewVC 1.1.26