30. [% FOREACH debt IN debts %] Dear [% debt.name %], You owe me £[% debt.amount %]. Please pay up by [% debt.date %] or I'll send the boys round. Love Dave... [% END %]
31. #!/usr/bin/perl use Template; use Debt; my $tt = Template->new; my @debts = Debt->find_all; $tt->process('template.tt', { debts => debts});
57. package Debt; use Moose; has name => (isa => 'Str', is => 'rw', required => 1); has amount => (isa => 'Num', is => 'rw', required => 1); has date => (isa => 'DateTime', is => 'rw');
58. #!/usr/bin/perl use 5.010; use strict; use warnings; use Debt; my $debt = Debt->new({ name => 'Joe Random', amount => 100, }); say $debt->name, ' owes £', $debt->amount; # Add interest $debt->amount($debt->amount * 1.1); say $debt->name, ' owes £', $debt->amount;
59. use DateTime; # Set due date $debt->date(DateTime->now->add(days => 28)); say $debt->date; # Easier to read say $debt->date->strftime('%A %d %B %Y');
75. $ catalyst.pl MyApp created "MyApp" created "MyApp/script" created "MyApp/lib" created "MyApp/root" created "MyApp/root/static" created "MyApp/root/static/images" created "MyApp/t" [ ... ] created "MyApp/Makefile.PL" created "MyApp/script/myapp_cgi.pl" created "MyApp/script/myapp_fastcgi.pl" created "MyApp/script/myapp_server.pl" created "MyApp/script/myapp_test.pl" created "MyApp/script/myapp_create.pl" Change to application directory and Run "perl Makefile.PL" to make sure your install is complete
76. $ cd MyApp $ script/myapp_server.pl [debug] Debug messages enabled [debug] Statistics enabled [debug] Loaded plugins: .----------------------------------------------------------------------------. | Catalyst::Plugin::ConfigLoader 0.27 | '----------------------------------------------------------------------------' [ ... lots of information ... ] [info] MyApp powered by Catalyst 5.80023 You can connect to your server at http://localhost:3000
104. use Plack::Request; use Plack::Response; use Data::Dumper; my $app = sub { my $req = Plack::Request->new(shift); my $res = Plack::Response->new(200); $res->content_type('text/plain'); $res->body(Dumper $req); return $res->finalize; }