/[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 1171 - (show annotations)
Sun Jul 5 21:25:25 2009 UTC (14 years, 9 months ago) by dpavlin
File size: 2334 byte(s)
add around title to setup application title
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 room {
11 App::RoomReservation::Room->new;
12 }
13
14 around 'title' => sub {
15 my ( $real_title, $self ) = @_;
16 return ( 'Seat Reservation' );
17 };
18
19 sub form_header {
20 my $self = shift;
21 $self->room->description;
22 }
23
24 sub form_footer {
25 qq|
26 <div style="font-size:75%; color: #888; clear: left;">
27 Insert some standard disclamer for every page here
28 </div>
29 |;
30 }
31
32 sub dsn { 'DBI:Pg:dbname=room-reservation' }
33
34 =head1 DEPLOY
35
36 createdb --encoding=utf-8 room-reservation
37
38 perl -Ilib -MFrey::Class::Schematize \
39 -e 'print Frey::Class::Schematize->new( class => "App::RoomReservation::Reservation" )->create_table,$/;' \
40 | psql room-reservation
41
42 =cut
43
44 our $dbh;
45 sub dbh {
46 my ($self) = @_;
47
48 return $dbh if defined $dbh;
49
50 $dbh = DBI->connect( $self->dsn, '', '', { RaiseError => 1 } ) || die $DBI::errstr;
51 $dbh->do( qq{ set client_encoding='utf-8' } ) if $self->dsn =~ m{pg}i;
52
53 return $dbh;
54 }
55
56 sub as_markup {
57 my ($self) = @_;
58
59
60 my $url = $self->url_for( 'Reservation/create_as_markup' );
61
62 return
63 $self->room->room_as_markup
64 . qq|<a target="App::RoomReservation::Reservation" href="$url">seat reservation</a>|
65 ;
66 }
67
68 # my $url = $self->uri_for( 'Reservation/create_as_makrup' );
69
70 sub url_mapping {{
71 "App::RoomReservation/as_markup" => 'zimbardo',
72 "App::RoomReservation::Reservation/create_as_markup" => 'zimbardo/create',
73 "App::RoomReservation::Confirmation/verify_as_markup?token=" => 'zimbardo/verify/',
74 "App::RoomReservation::Confirmation/cancel_as_markup?token=" => 'zimbardo/cancel/',
75 }}
76
77 our $urls;
78 use Data::Dump qw/dump/;
79
80 sub url_for {
81 my $self = shift;
82 my $to = shift;
83 my $args = join('', @_);
84 my $app = ref($self);
85 $app =~ s{^(App::[^:]+)::.+$}{$1};
86 $app .= '::' . $to;
87
88 my ( $class, $method ) = split(m{/}, $app);
89 $method =~ s{\?.+$}{}; # remove arguments
90 Class::MOP::load_class( $class );
91 die "$class doesn't implement $method" unless $class->meta->has_method($method);
92
93 $urls->{$app}++;
94 warn "XXX urls = ",dump($urls);
95
96 my $map_to = url_mapping->{$app};
97 $app = $map_to if $map_to;
98
99 return
100 $self->request_url->scheme . '://' . $self->request_url->authority . '/' . $app . $args;
101 }
102
103 __PACKAGE__->meta->make_immutable;
104 no Moose;
105
106 1;

  ViewVC Help
Powered by ViewVC 1.1.26