summaryrefslogtreecommitdiffstats
path: root/lib/Narwhal/Component/Wiki/Page.pm
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2011-02-17 18:57:19 -0600
committerJesse Luehrs <doy@tozt.net>2011-02-17 18:57:19 -0600
commita7c37d5489611bf79889dd689abb0ac686d640c9 (patch)
tree68d9b965c581dcc049c36b5e6a5d9b877ff0312b /lib/Narwhal/Component/Wiki/Page.pm
parent251066735d9b3392ba7ea35da2fc0d6cd896e3a1 (diff)
downloadnarwhal-a7c37d5489611bf79889dd689abb0ac686d640c9.tar.gz
narwhal-a7c37d5489611bf79889dd689abb0ac686d640c9.zip
refactor this a bit
Diffstat (limited to 'lib/Narwhal/Component/Wiki/Page.pm')
-rw-r--r--lib/Narwhal/Component/Wiki/Page.pm53
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/Narwhal/Component/Wiki/Page.pm b/lib/Narwhal/Component/Wiki/Page.pm
new file mode 100644
index 0000000..726439a
--- /dev/null
+++ b/lib/Narwhal/Component/Wiki/Page.pm
@@ -0,0 +1,53 @@
+package Narwhal::Component::Wiki::Page;
+use Moose;
+
+has kioku => (
+ isa => 'KiokuX::Model',
+ required => 1,
+ handles => 'KiokuDB::Role::API',
+);
+
+has tt => (
+ isa => 'Template',
+ required => 1,
+ handles => ['process'],
+);
+
+has scope => (
+ is => 'ro',
+ isa => 'KiokuDB::LiveObjects::Scope',
+ lazy => 1,
+ default => sub { shift->new_scope },
+);
+
+sub BUILD {
+ my $self = shift;
+ $self->scope;
+}
+
+sub get {
+ my $self = shift;
+ my ($req, $page) = @_;
+
+ my $page_obj = $self->lookup("page:$page");
+ return $req->new_response(404)
+ unless $page_obj;
+
+ my $out;
+ $self->process(
+ 'page.tt',
+ {
+ uri_for => sub { $req->uri_for({@_}) },
+ text => $page_obj->text,
+ page => $page
+ },
+ \$out
+ );
+
+ return $req->new_response(200, [], $out);
+}
+
+__PACKAGE__->meta->make_immutable;
+no Moose;
+
+1;