[Bps-public-commit] r11195 - WebChart/lib
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Wed Mar 26 07:16:10 EDT 2008
Author: sunnavy
Date: Wed Mar 26 07:15:44 2008
New Revision: 11195
Modified:
WebChart/lib/WebChart.pm
Log:
implement WebChart.pm
Modified: WebChart/lib/WebChart.pm
==============================================================================
--- WebChart/lib/WebChart.pm (original)
+++ WebChart/lib/WebChart.pm Wed Mar 26 07:15:44 2008
@@ -3,9 +3,85 @@
use warnings;
use strict;
use Carp;
+use UNIVERSAL::require;
our $VERSION = '0.01';
+use base qw/Class::Accessor::Fast/;
+
+__PACKAGE__->mk_accessors(qw/renderer img_dir web_img_dir css_classes/);
+
+=head2 new
+
+create a new WebChart object
+
+e.g.
+
+%args = ( renderer => 'WebChart::Renderer::Chart', img_dir => '/tmp',
+ web_img_dir => '/charts', css_classes => [ 'foo', 'bar' ] )
+
+=cut
+
+
+sub new {
+
+ my $class = shift;
+ my %args = @_;
+ my $self = bless {}, $class;
+
+ $self->init(%args);
+ return $self;
+}
+
+
+=head2 init
+
+init job is done here, you don't need to call this directly, please call new.
+
+=cut
+
+sub init {
+ my $self = shift;
+ my %args = @_;
+ my $renderer = $args{renderer} || 'WebChart::Renderer::Chart';
+ $renderer = 'WebChart::Renderer::' . $renderer
+ unless $renderer =~ /^WebChart::/;
+ $renderer->require or die "can't require $renderer: $!";
+ $self->renderer( $renderer->new );
+
+ my $img_dir = $args{img_dir};
+
+ unless ($img_dir) {
+ require File::Spec;
+ $img_dir = File::Spec->tmpdir();
+ }
+
+ $self->img_dir($img_dir);
+
+ $self->web_img_dir( $args{web_img_dir} || '/charts' );
+
+ $self->css_classes( $args{css_classes} || [] );
+}
+
+=head2 render
+
+render pictures.
+
+%args = ( width => 400, height => 300, data = [ ... ] )
+you can also supply img_dir, web_img_dir and css_classes args to overwrite
+things the WebChart object already have
+
+=cut
+
+sub render {
+ my $self = shift;
+ return $self->renderer->render(
+ img_dir => $self->img_dir,
+ web_img_dir => $self->web_img_dir,
+ css_classes => $self->css_classes,
+ @_,
+ );
+}
1;
@@ -54,7 +130,7 @@
=head1 LICENCE AND COPYRIGHT
-Copyright 2008 Best Practical Solutions.
+Copyright 2007 Best Practical Solutions.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
More information about the Bps-public-commit
mailing list