| 1 | package HTML::Display::TempFile; | ||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | 2 | ▶ | use parent 'HTML::Display::Common'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use vars qw($VERSION); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 2 | $VERSION='0.40'; | |||||||||
| 6 | |||||||||||
| 7 | =head1 NAME | ||||||||||
| 8 | |||||||||||
| 9 | HTML::Display::TempFile - base class to display HTML via a temporary file | ||||||||||
| 10 | |||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||
| 12 | |||||||||||
| 13 | =for example begin | ||||||||||
| 14 | |||||||||||
| 15 | 1 | ▶ | package HTML::Display::External; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | use parent 'HTML::Display::TempFile'; | ||||||||||
| 17 | |||||||||||
| 18 | sub browsercmd { | ||||||||||
| 19 | # Return the string to pass to system() | ||||||||||
| 20 | # %s will be replaced by the temp file name | ||||||||||
| 21 | }; | ||||||||||
| 22 | |||||||||||
| 23 | =for example end | ||||||||||
| 24 | |||||||||||
| 25 | =cut | ||||||||||
| 26 | |||||||||||
| 27 | 1 | ▶ | sub display_html { | ||||||||
|
Subroutine
display_html: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 28 | # We need to use a temp file for communication | ||||||||||
| 29 | 1 | my ($self,$html) = @_; | |||||||||
| 30 | |||||||||||
| 31 | 1 | $self->cleanup_tempfiles; | |||||||||
| 32 | |||||||||||
| 33 | 1 | require File::Temp; | |||||||||
| 34 | 1 | my($tempfh, $tempfile) = File::Temp::tempfile(SUFFIX => '.html'); | |||||||||
| 35 | 1 | print $tempfh $html; | |||||||||
| 36 | 1 | close $tempfh; | |||||||||
| 37 | |||||||||||
| 38 | 1 | push @{$self->{delete}}, $tempfile; | |||||||||
| 39 | |||||||||||
| 40 | 1 | my $cmdline = sprintf($self->browsercmd, $tempfile); | |||||||||
| 41 | 1 | ▶ | system( $cmdline ) == 0 | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | or warn "Couldn't launch '$cmdline' : $?"; | ||||||||||
| 43 | }; | ||||||||||
| 44 | |||||||||||
| 45 | 1 | ▶ | sub cleanup_tempfiles { | ||||||||
|
Subroutine
cleanup_tempfiles: called CC=3 SCAR=13.1
Pod
undocumented
| |||||||||||
| 46 | 1 | my ($self) = @_; | |||||||||
| 47 | 1 | for my $file (@{$self->{delete}}) { | |||||||||
| 48 | 0 | ▶ | unlink $file | ||||||||
|
Branch: 1 branch
| |||||||||||
| 49 | or warn "Couldn't remove tempfile $file : $!\n"; | ||||||||||
| 50 | }; | ||||||||||
| 51 | 1 | $self->{delete} = []; | |||||||||
| 52 | }; | ||||||||||
| 53 | |||||||||||
| 54 | 0 | ▶ | sub browsercmd { $_[0]->{browsercmd} }; | ||||||||
|
Subroutine
browsercmd: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 55 | |||||||||||
| 56 | =head1 AUTHOR | ||||||||||
| 57 | |||||||||||
| 58 | Copyright (c) 2004-2013 Max Maischein C<< <corion@cpan.org> >> | ||||||||||
| 59 | |||||||||||
| 60 | =head1 LICENSE | ||||||||||
| 61 | |||||||||||
| 62 | This module is released under the same terms as Perl itself. | ||||||||||
| 63 | |||||||||||
| 64 | =cut | ||||||||||
| 65 | |||||||||||
| 66 | 2 | 1; | |||||||||