Skip Menu |
 

This queue is for tickets about the Data-Google-Visualization-DataTable CPAN distribution.

Report information
The Basics
Id: 64356
Status: resolved
Priority: 0/
Queue: Data-Google-Visualization-DataTable

People
Owner: Nobody in particular
Requestors: matthew [...] mdarwin.ca
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 0.06
Fixed in: (no value)



Subject: There is no way to send properties
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 2677
Download (untitled) / with headers
text/plain 2.6k
There needs to be a way to set property values in the data. The following code adds a new method add_property() for this purpose. *** /usr/local/share/perl/5.10.1/Data/Google/Visualization/DataTable.pm.orig Thu Dec 30 21:03:21 2010 --- /usr/local/share/perl/5.10.1/Data/Google/Visualization/DataTable.pm Thu Dec 30 21:37:41 2010 *************** *** 153,162 **** sub new { my $class = shift; my $self = { columns => [], column_mapping => {}, rows => [], ! json_xs => JSON::XS->new()->canonical(1), all_columns_have_ids => 0, column_count => 0, pedantic => 1 --- 153,163 ---- sub new { my $class = shift; my $self = { + properties => {}, columns => [], column_mapping => {}, rows => [], ! json_xs => JSON::XS->new()->canonical(1)->allow_nonref, all_columns_have_ids => 0, column_count => 0, pedantic => 1 *************** *** 467,472 **** --- 468,490 ---- return $self; } + =head2 add_property + + There is the ability to add arbitrary values + + $object->add_property(key, value); + + =cut + + sub add_property { + my ($self, $key, $value) = @_; + + my $json_key = $self->json_xs_object->encode( $key ); + my $json_value = $self->json_xs_object->encode( $value ); + + ${$self->{properties}}{$json_key} = $json_value; + } + =head2 pedantic We do some data checking for sanity, and we'll issue warnings about things the *************** *** 535,540 **** --- 553,560 ---- } @$rows; my $rows_string = join ',' . $n . $t . $t, @rows; + my $properties_string = join ',' .$n.$t.$t, map { $_ .":" . ${$self->{properties}}{$_} } (keys %{$self->{properties}}); + return '{' .$n. $t. '"cols": [' .$n. *************** *** 542,548 **** $t. '],' .$n. $t. '"rows": [' .$n. $t. $t. $rows_string .$n. ! $t. ']' .$n. '}'; } --- 562,571 ---- $t. '],' .$n. $t. '"rows": [' .$n. $t. $t. $rows_string .$n. ! $t. '],' .$n. ! $t. '"p": {' .$n. ! $t. $t. $properties_string .$n. ! $t. '}' .$n. '}'; }
MIME-Version: 1.0
Subject: There is no way to send properties (diff attached)
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Type: multipart/mixed; boundary="----------=_1293764252-17550-247"
Message-ID: <rt-3.8.HEAD-17550-1293764252-1711.64356-0-0 [...] rt.cpan.org>
X-RT-Original-Encoding: utf-8
Content-Length: 0
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 17
Attached the diff
MIME-Version: 1.0
Subject: DataTable.diff
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Type: text/x-patch; name="DataTable.diff"
Content-Disposition: inline; filename="DataTable.diff"
Content-Transfer-Encoding: binary
Content-Length: 2117
Download DataTable.diff
text/x-diff 2k
*** /usr/local/share/perl/5.10.1/Data/Google/Visualization/DataTable.pm.orig Thu Dec 30 21:03:21 2010 --- /usr/local/share/perl/5.10.1/Data/Google/Visualization/DataTable.pm Thu Dec 30 21:37:41 2010 *************** *** 153,162 **** sub new { my $class = shift; my $self = { columns => [], column_mapping => {}, rows => [], ! json_xs => JSON::XS->new()->canonical(1), all_columns_have_ids => 0, column_count => 0, pedantic => 1 --- 153,163 ---- sub new { my $class = shift; my $self = { + properties => {}, columns => [], column_mapping => {}, rows => [], ! json_xs => JSON::XS->new()->canonical(1)->allow_nonref, all_columns_have_ids => 0, column_count => 0, pedantic => 1 *************** *** 467,472 **** --- 468,490 ---- return $self; } + =head2 add_property + + There is the ability to add arbitrary values + + $object->add_property(key, value); + + =cut + + sub add_property { + my ($self, $key, $value) = @_; + + my $json_key = $self->json_xs_object->encode( $key ); + my $json_value = $self->json_xs_object->encode( $value ); + + ${$self->{properties}}{$json_key} = $json_value; + } + =head2 pedantic We do some data checking for sanity, and we'll issue warnings about things the *************** *** 535,540 **** --- 553,560 ---- } @$rows; my $rows_string = join ',' . $n . $t . $t, @rows; + my $properties_string = join ',' .$n.$t.$t, map { $_ .":" . ${$self->{properties}}{$_} } (keys %{$self->{properties}}); + return '{' .$n. $t. '"cols": [' .$n. *************** *** 542,548 **** $t. '],' .$n. $t. '"rows": [' .$n. $t. $t. $rows_string .$n. ! $t. ']' .$n. '}'; } --- 562,571 ---- $t. '],' .$n. $t. '"rows": [' .$n. $t. $t. $rows_string .$n. ! $t. '],' .$n. ! $t. '"p": {' .$n. ! $t. $t. $properties_string .$n. ! $t. '}' .$n. '}'; }
MIME-Version: 1.0
X-Mailer: MIME-tools 5.427 (Entity 5.427)
Content-Disposition: inline
Content-Type: text/plain; charset="UTF-8"
Message-ID: <rt-3.8.HEAD-19313-1293792032-873.64356-0-0 [...] rt.cpan.org>
Content-Transfer-Encoding: binary
X-RT-Original-Encoding: utf-8
Content-Length: 106
Download (untitled) / with headers
text/plain 106b
Looking in to this revealed a couple of other problems with properties. All are now fixed in 0.07. Thanks!


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.