[Bps-public-commit] r11396 - in WebChart: t
sunnavy at bestpractical.com
sunnavy at bestpractical.com
Wed Apr 2 11:15:04 EDT 2008
Author: sunnavy
Date: Wed Apr 2 11:14:24 2008
New Revision: 11396
Modified:
WebChart/lib/WebChart.pm
WebChart/t/webchart.t
Log:
added options arg
Modified: WebChart/lib/WebChart.pm
==============================================================================
--- WebChart/lib/WebChart.pm (original)
+++ WebChart/lib/WebChart.pm Wed Apr 2 11:14:24 2008
@@ -11,7 +11,7 @@
__PACKAGE__->mk_accessors(
qw/renderer img_dir web_img_dir xml_dir web_xml_dir web_js_dir
- web_flash_dir web_css_dir css_class width height/
+ web_flash_dir web_css_dir css_class width height options/
);
=head2 new
@@ -32,6 +32,7 @@
css_class => 'foo bar',
width => 400,
height => 300,
+ options => { 'legend_labels' => ['foo', 'bar'] }
);
=cut
@@ -86,6 +87,7 @@
$self->css_class( $args{css_class} );
$self->width( $args{width} || 400 );
$self->height( $args{height} || 300 );
+ $self->options( $args{options} || {} );
}
=head2 render
@@ -102,6 +104,7 @@
sub render {
my $self = shift;
my %args = @_;
+ my $options = delete $args{options} || {};
for (qw/type data/) {
croak "need to set $_ arg" unless $args{$_};
@@ -109,13 +112,14 @@
return $self->renderer->render(
(
- map { $_ => $self->$_ } (
+ options => { %{$self->options}, %$options },
+ map( { $_ => $self->$_ } (
qw/img_dir css_class width height xml_dir
web_img_dir web_js_dir web_flash_dir
web_xml_dir web_css_dir/
- )
+ )),
+ %args,
),
- @_,
);
}
Modified: WebChart/t/webchart.t
==============================================================================
--- WebChart/t/webchart.t (original)
+++ WebChart/t/webchart.t Wed Apr 2 11:14:24 2008
@@ -5,7 +5,7 @@
use WebChart;
use File::Spec;
-use Test::More tests => 41;
+use Test::More tests => 42;
my $wc = WebChart->new;
my %default = (
@@ -18,11 +18,12 @@
web_css_dir => '/css',
width => 400,
height => 300,
+ options => {},
css_class => undef,
);
for ( keys %default ) {
- is( $wc->$_, $default{$_},
+ is_deeply( $wc->$_, $default{$_},
"default $_ is " . ( defined $default{$_} ? $default{$_} : 'undef' ) );
}
@@ -93,12 +94,15 @@
web_js_dir => 'ring',
web_flash_dir => 'gandolf',
web_css_dir => '/ring',
+ options => { foo => 'bar' },
);
+$wc->options( { baz => 'baz', foo => 'baz' } );
%return = $wc->render(%args);
+
is_deeply(
\%return,
- { %default, %args },
- "args can be supplied that overwrides the WebChart object's default value"
+ { %default, %args, options => { foo => 'bar', baz => 'baz' } },
+ "args can be supplied that overwrides the WebChart object's default value, and options will be merged"
);
eval { $wc->render( type => 'bars' ); };
More information about the Bps-public-commit
mailing list