[Jifty-commit] r3737 - in jifty/trunk: .
jifty-commit at lists.jifty.org
jifty-commit at lists.jifty.org
Sun Jul 29 22:16:37 EDT 2007
Author: sterling
Date: Sun Jul 29 22:16:37 2007
New Revision: 3737
Modified:
jifty/trunk/ (props changed)
jifty/trunk/lib/Jifty/Plugin/Chart/Dispatcher.pm
jifty/trunk/lib/Jifty/Plugin/Chart/View.pm
Log:
r8205 at dynpc145: andrew | 2007-07-29 21:15:43 -0500
Regarding Jifty::Plugin::Chart: Added better comments. Fixed some error handling. Switched to using scalar_png(). Switched to using ->require rather than an eval to load Chart classes. Eliminated the need for IO::String. Moved some processing out of View and into Dispatcher.
Modified: jifty/trunk/lib/Jifty/Plugin/Chart/Dispatcher.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Chart/Dispatcher.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/Chart/Dispatcher.pm Sun Jul 29 22:16:37 2007
@@ -19,13 +19,26 @@
=cut
on 'chart/*' => run {
+ # Create a session ID to lookup the chart configuration
my $session_id = 'chart_' . $1;
+ # Unpack the data and then clear it from the session
my $args = Jifty::YAML::Load( Jifty->web->session->get( $session_id ) );
Jifty->web->session->remove( $session_id );
+ # No data? Act like a 404
last_rule unless defined $args;
+ # Use the "type" to determine which class to use
+ my $class = 'Chart::' . $args->{type};
+
+ # Load that class or die if it does not exist
+ $class->require;
+
+ # Remember the class name for the view
+ $args->{class} = $class;
+
+ # Send them on to chart the chart
set 'args' => $args;
show 'chart';
};
@@ -36,7 +49,7 @@
=head1 AUTHOR
-Andrew Sterling Hanenkamp E<< <andrew.hanenkamp at boomer.com> >>
+Andrew Sterling Hanenkamp C<< <andrew.hanenkamp at boomer.com> >>
=head1 COPYRIGHT AND LICENSE
Modified: jifty/trunk/lib/Jifty/Plugin/Chart/View.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/Chart/View.pm (original)
+++ jifty/trunk/lib/Jifty/Plugin/Chart/View.pm Sun Jul 29 22:16:37 2007
@@ -4,8 +4,6 @@
package Jifty::Plugin::Chart::View;
use Jifty::View::Declare -base;
-use IO::String;
-
=head1 NAME
Jifty::Plugin::Chart::View - Views for the renderers built into the Chart plugin
@@ -24,21 +22,22 @@
# Load the arguments
my $args = get 'args';
- # Use the "type" to determine which class to use
- my $class = 'Chart::' . $args->{type};
-
- # Load that class or die if it does not exist
- eval "use $class";
- die $@ if $@;
# Set the output type to the PNG file type
Jifty->handler->apache->content_type('image/png');
# Render the chart and output the PNG file generated
- my $fh = IO::String->new;
- my $chart = $class->new( $args->{width}, $args->{height} );
- $chart->png($fh, $args->{data});
- outs_raw( ${ $fh->string_ref } )
+ eval {
+ my $chart = $args->{class}->new( $args->{width}, $args->{height} );
+ # XXX scalar_png() is undocumented!!! Might bad to rely upon.
+ outs_raw($chart->scalar_png($args->{data}));
+ };
+
+ # Should have thrown an error if bad stuff happened, handle that
+ if ($@) {
+ Jifty->log->error("Failed to render chart: $@");
+ die $@;
+ }
};
=head1 SEE ALSO
More information about the Jifty-commit
mailing list