Question

Recently, I've found plot.ly site and am trying to use it. But, When I use Perl API, I can't success. My steps are same below.

  1. I sign up plot.ly with google account
  2. Installed Perl module(WebService::Plotly)
  3. Type basic example("https://plot.ly/api/perl/docs/line-scatter")

..skip..

use WebService::Plotly;
use v5.10;
use utf8;

my $user = "MYID";
my $key = "MYKEY";

my $py= WebService::Plotly->new( un => $user, key => $key );

say __LINE__; # first say

my $x0 = [1,2,3,4]; 
my $y0 = [10,15,13,17];
my $x1 = [2,3,4,5]; 
my $y1 = [16,5,11,9];

my $response = $py->plot($x0, $y0, $x1, $y1);
say __LINE__ ; # second say

..skip...

Then, Execute example perl code =>> But, In this step, $py->plot always returned "HTTP::Response=HASH(0x7fd1a4236918)" and second say is not exeucted ( I used Perl version 5.16.2 and 5.19.1, OS is MacOS X)

On the hands, python example("https://plot.ly/api/python/docs/line-scatter") is always succeed.

Please, let me know this problem. Thanks a lot!

Was it helpful?

Solution

After fast look at source code of this module I can suggest to use it like in example below. Because any method may raise exception. On http error this will be HTTP::Response object

eval {
    my $response = $py->plot($x0, $y0, $x1, $y1);
};
if (my $err = $@) {
    if (!ref $err) {
        die "Plotly error: ", $err;
    }
    elsif ($err->isa('HTTP::Response')) {
        die "HTTP error: ", $err->status_line;
    }
    else {
        die "Unknown error: ", ref($err), " ($err)"
    }
}

OTHER TIPS

Have you looked at $py->content or any of the other attributes to the HTTP::Response object?

You have't told us anything other than that you've tried to print the value of an object reference, the output that you have provided from that, is the output one would expect.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top