| 1 | package Gnuplot::Builder::TempFile; | ||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use Exporter qw(import); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use File::Temp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use File::Spec; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 1 | ▶ | use IPC::Open3 qw(open3); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | 1 | ▶ | use Gnuplot::Builder 0.13 (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 1 | ▶ | use Gnuplot::Builder::Process; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 1 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | |||||||||||
| 12 | 1 | our $VERSION = "0.03"; | |||||||||
| 13 | |||||||||||
| 14 | 1 | our @EXPORT_OK = qw(run); | |||||||||
| 15 | |||||||||||
| 16 | { | ||||||||||
| 17 | 1 | my $null_handle; | |||||||||
| 18 | |||||||||||
| 19 | 0 | ▶ | sub _null_handle { | ||||||||
|
Subroutine
_null_handle: not called CC=3 SCAR=24.8
| |||||||||||
| 20 | 0 | ▶ | return $null_handle if defined $null_handle; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 21 | 0 | my $devnull = File::Spec->devnull; | |||||||||
| 22 | 0 | ▶ | open $null_handle, ">", $devnull or confess("Cannot open $devnull: $!"); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 0 | return $null_handle; | |||||||||
| 24 | } | ||||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 1 | ▶ | sub run { | ||||||||
|
Subroutine
run: not called CC=2 SCAR=16.6
Pod
documented
| |||||||||||
| 28 | 0 | my (@gnuplot_command) = @_; | |||||||||
| 29 | 0 | local $| = 1; | |||||||||
| 30 | 0 | ▶ | if(!@gnuplot_command) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 31 | 0 | @gnuplot_command = qw(gnuplot --persist); | |||||||||
| 32 | } | ||||||||||
| 33 | 0 | my $tempfile = File::Temp->new; | |||||||||
| 34 | 0 | $tempfile->unlink_on_destroy(0); | |||||||||
| 35 | 0 | ▶ | Gnuplot::Builder::Process::MockTool::receive_from_builder *STDIN, *STDOUT, sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 36 | 0 | my ($data) = @_; | |||||||||
| 37 | 0 | $tempfile->print($data); | |||||||||
| 38 | 0 | }; | |||||||||
| 39 | 0 | $tempfile->close; | |||||||||
| 40 | 0 | _execute(@gnuplot_command, $tempfile->filename); | |||||||||
| 41 | 0 | _execute("gnuplot_builder_tempfile_remover", $tempfile->filename); | |||||||||
| 42 | } | ||||||||||
| 43 | |||||||||||
| 44 | 0 | ▶ | sub _execute { | ||||||||
|
Subroutine
_execute: not called CC=1 SCAR=6.9
| |||||||||||
| 45 | 0 | my (@command) = @_; | |||||||||
| 46 | 0 | my $pid = open3(my $in, _null_handle(), undef, @command); | |||||||||
| 47 | 0 | close $in; | |||||||||
| 48 | 0 | return $pid; | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | 1 | 1; | |||||||||
| 52 | __END__ | ||||||||||