| 1 | package Chart::Plotly::Image::Orca::Client; | ||||||||||
| 2 | |||||||||||
| 3 | # ABSTRACT: Export static images of Plotly charts using orca server | ||||||||||
| 4 | |||||||||||
| 5 | 1 | ▶ | use 5.010; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 1 | ▶ | use Path::Tiny; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use LWP::UserAgent; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | 1 | our $VERSION = '0.042'; # VERSION | |||||||||
| 14 | |||||||||||
| 15 | 0 | ▶ | sub save_image { | ||||||||
|
Subroutine
save_image: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 16 | 0 | my %params = @_; | |||||||||
| 17 | |||||||||||
| 18 | 0 | my $plot = $params{plot}; | |||||||||
| 19 | 0 | my $file = path( $params{file} ); | |||||||||
| 20 | |||||||||||
| 21 | 0 | my $ua = LWP::UserAgent->new; | |||||||||
| 22 | 0 | $ua->agent("Chart::Plotly::Image::Orca::Client/0.1"); | |||||||||
| 23 | |||||||||||
| 24 | 0 | my $req = HTTP::Request->new( POST => $params{server} ); | |||||||||
| 25 | 0 | $req->content_type('application/json'); | |||||||||
| 26 | 0 | $req->content( $plot->to_json_text ); | |||||||||
| 27 | 0 | my $res = $ua->request($req); | |||||||||
| 28 | 0 | ▶ | if ( $res->is_success ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 29 | 0 | path($file)->spew_raw( $res->content ); | |||||||||
| 30 | } else { | ||||||||||
| 31 | 0 | die "Can't export the plot. Server returned: " . $res->status_line; | |||||||||
| 32 | } | ||||||||||
| 33 | 0 | return; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 1 | 1; | |||||||||
| 37 | |||||||||||
| 38 | __END__ | ||||||||||