/[Frey]/trunk/lib/App/RoomReservation.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

Contents of /trunk/lib/App/RoomReservation.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1155 - (show annotations)
Thu Jul 2 10:12:54 2009 UTC (14 years, 9 months ago) by dpavlin
File size: 1441 byte(s)
allow users to cancel lecture seat only once
1 package App::RoomReservation;
2 use Moose;
3
4 extends 'Frey';
5 with 'Frey::Web';
6
7 use lib 'lib';
8 use App::RoomReservation::Room;
9
10 sub dsn { 'DBI:Pg:dbname=room-reservation' }
11
12 =head1 DEPLOY
13
14 createdb --encoding=utf-8 room-reservation
15
16 perl -Ilib -MFrey::Class::Schematize \
17 -e 'print Frey::Class::Schematize->new( class => "App::RoomReservation::Reservation" )->create_table,$/;' \
18 | psql room-reservation
19
20 =cut
21
22 our $dbh;
23 sub dbh {
24 my ($self) = @_;
25
26 return $dbh if defined $dbh;
27
28 $dbh = DBI->connect( $self->dsn, '', '', { RaiseError => 1 } ) || die $DBI::errstr;
29 $dbh->do( qq{ set client_encoding='utf-8' } ) if $self->dsn =~ m{pg}i;
30
31 return $dbh;
32 }
33
34 sub as_markup {
35 my ($self) = @_;
36
37
38 my $url = $self->url_for( 'Reservation/create_as_markup' );
39
40 return
41 App::RoomReservation::Room->new->room_as_markup
42 . qq|<a target="App::RoomReservation::Reservation" href="$url">seat reservation</a>|
43 ;
44 }
45
46 # my $url = $self->uri_for( 'Reservation/create_as_makrup' );
47
48 sub url_for {
49 my ( $self, $to ) = @_;
50 my $app = ref($self);
51 $app =~ s{^(App::[^:]+)::.+$}{$1};
52 $app .= '::' . $to;
53
54 my ( $class, $method ) = split(m{/}, $app);
55 $method =~ s{\?.+$}{}; # remove arguments
56 Class::MOP::load_class( $class );
57 die "$class doesn't implement $method" unless $class->meta->has_method($method);
58
59 return
60 $self->request_url->scheme . '://' . $self->request_url->authority . '/' . $app;
61 }
62
63 __PACKAGE__->meta->make_immutable;
64 no Moose;
65
66 1;

  ViewVC Help
Powered by ViewVC 1.1.26