1# 2# (c) Jan Gehring <jan.gehring@gmail.com> 3# 4# vim: set ts=2 sw=2 tw=0: 5# vim: set expandtab: 6 7package Rex::Output; 8 9use 5.010001; 10use strict; 11use warnings; 12 13my $handle; 14use vars qw($output_object); 15 16BEGIN { IPC::Shareable->use; } 17END { IPC::Shareable->clean_up_all; } 18 19use base 'Rex::Output::Base'; 20 21our $VERSION = '1.13.4'; # VERSION 22 23sub get { 24 my ( $class, $output_module ) = @_; 25 26 return $output_object if ($output_object); 27 28 return unless ($output_module); 29 30 $handle = tie $output_object, 'IPC::Shareable', undef, { destroy => 1 } 31 unless $handle; 32 33 eval "use Rex::Output::$output_module;"; 34 if ($@) { 35 die("Output Module ,,$output_module'' not found."); 36 } 37 38 my $output_class = "Rex::Output::$output_module"; 39 $output_object = $output_class->new; 40 41 return $class; 42} 43 44sub _action { 45 my ( $class, $action, @args ) = @_; 46 47 return unless ( defined $output_object ); 48 $handle->shlock(); 49 $output_object->$action(@args); 50 $handle->shunlock(); 51} 52 53sub add { 54 my $class = shift; 55 56 return $class->_action( 'add', @_ ); 57} 58 59sub error { 60 my $class = shift; 61 62 return $class->_action( 'error', @_ ); 63} 64 65sub write { 66 my $class = shift; 67 68 return $class->_action( 'write', @_ ); 69} 70 711; 72