[Bps-public-commit] r11234 - in WebChart/lib/WebChart: Renderer

sunnavy at bestpractical.com sunnavy at bestpractical.com
Thu Mar 27 10:16:01 EDT 2008


Author: sunnavy
Date: Thu Mar 27 10:15:59 2008
New Revision: 11234

Modified:
   WebChart/lib/WebChart/Renderer.pm
   WebChart/lib/WebChart/Renderer/Chart.pm

Log:
updated Renderer.pm and Renderer/Chart.pm to pass tests

Modified: WebChart/lib/WebChart/Renderer.pm
==============================================================================
--- WebChart/lib/WebChart/Renderer.pm	(original)
+++ WebChart/lib/WebChart/Renderer.pm	Thu Mar 27 10:15:59 2008
@@ -27,15 +27,20 @@
 
 =head2 render
 
-you should subclass this
+you should subclass this and call this as SUPER way
 
 =cut
 
 sub render {
     my $self = shift;
-    for (qw/type data/) {
-        croak "need $_ arg" unless $args{type};
+    my $args = shift;
+    $args->{web_img_dir} ||= '/charts';
+    unless ( $args->{img_dir} ) {
+        require File::Spec;
+        $args->{img_dir} = File::Spec->tmpdir;
     }
+    delete $args->{css_class}
+      unless $args->{css_class} && $args->{css_class} =~ /\w/;
 }
 
 1;

Modified: WebChart/lib/WebChart/Renderer/Chart.pm
==============================================================================
--- WebChart/lib/WebChart/Renderer/Chart.pm	(original)
+++ WebChart/lib/WebChart/Renderer/Chart.pm	Thu Mar 27 10:15:59 2008
@@ -3,7 +3,11 @@
 use warnings;
 use Carp;
 
+
 use base qw/ WebChart::Renderer /;
+use UNIVERSAL::require;
+use File::Spec;
+use File::Temp;
 
 =head2 render
 
@@ -17,6 +21,8 @@
     my $self = shift;
     my %args = @_;
 
+    $self->SUPER::render( \%args );
+
     # Conversion from generic types to Chart types
     my %types = (
         'bars'           => 'Bars',
@@ -43,7 +49,6 @@
     my $chart = $class->new( $args{width}, $args{height} );
     $chart->set( %{ $args{options} } ) if $args{options};
 
-    require File::Temp;
     my ( $fd, $filename ) = File::Temp::tempfile(
         'wc_XXXXXX',
         SUFFIX  => '.png',
@@ -52,12 +57,10 @@
     );
     $chart->png( $fd, $args{data} );
 
-    require File::Spec;
-
     my $seg = qq[<img src="$args{web_img_dir}/]
       . ( File::Spec->splitpath($filename) )[2] . q{"};
 
-    if ( $args{css_class}  ) {
+    if ( $args{css_class} ) {
         $seg .= qq{ class="$args{css_class}"};
     }
 



More information about the Bps-public-commit mailing list