summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Woodward2010-06-09 22:25:43 -0400
committerJason Woodward2010-06-09 22:27:29 -0400
commit5ecda0559c974fec0b81e3081285299cdcf48e1f (patch)
tree65fbf2ac50ef82edcfc2cf88afaf20ef8c6503fb
parent1f127d3fb5015c99dc3ebda24a67238f3c93a250 (diff)
downloadJaos-WebApp-5ecda0559c974fec0b81e3081285299cdcf48e1f.tar.gz
added ::Render::Data
-rw-r--r--Changes1
-rw-r--r--lib/Jaos/WebApp/Render/Data.pm75
2 files changed, 76 insertions, 0 deletions
diff --git a/Changes b/Changes
index 06a2f48..f282fb5 100644
--- a/Changes
+++ b/Changes
@@ -1,5 +1,6 @@
0.3 June 09, 2010
+ * added ::Render::Data
* properly report plugin register failure
* Updated ParamConstraint
diff --git a/lib/Jaos/WebApp/Render/Data.pm b/lib/Jaos/WebApp/Render/Data.pm
new file mode 100644
index 0000000..77697ec
--- /dev/null
+++ b/lib/Jaos/WebApp/Render/Data.pm
@@ -0,0 +1,75 @@
+package Jaos::WebApp::Render::Data;
+use strict;
+use warnings;
+
+sub register
+{
+ my ($class, $app, $conf) = @_;
+
+ $app->add_renderer(
+ data => sub {
+ my ($controller, $data, $options) = @_;
+
+ my $content_type = $options->{content_type} || 'application/octet-stream';
+ my $content_length = length($$data);
+
+ $controller->app->res->content_type($content_type);
+ $controller->app->res->content_length($content_length);
+ $controller->app->res->body($$data);
+ }
+ );
+}
+
+=head1 NAME
+
+Jaos::WebApp::Render::Data - Render output data
+
+=head1 SYNOPSIS
+
+ package MyApp::Controller;
+ use base qw/Jaos::WebApp/;
+ sub startup
+ {
+ my $app = shift;
+ $app->load_plugin('Jaos::WebApp::Render::Data');
+ $app->connect('/attachment/', controller => 'MyApp::Controller', action => 'attachment');
+ }
+
+ package MyApp::Controller;
+ use base qw/Jaos::WebApp::Controller/;
+ sub attachment
+ {
+ my $self = shift;
+ open(my $fh,'<','/path/to/data');
+ my $data;
+ {
+ local $/;
+ $data = <$fh>
+ }
+ close($fh);
+
+ $self->render( raw => \$data, { content_type => 'application/octet-stream'});
+ }
+ 1;
+
+=head1 DESCRIPTION
+
+This is a data renderer for L<Jaos::WebApp>.
+
+=head1 METHODS
+
+=head2 register
+
+Called by the L<Jaos::WebApp> plugin loader.
+
+=head1 AUTHOR
+
+Jason Woodward <woodwardj@jaos.org>
+
+=head1 LICENSE
+
+This library is free software; you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+1;