File Coverage

blib/lib/Safe/World/stderr.pm
Criterion Covered Total %
statement 12 53 22.6
branch 0 12 0.0
condition n/a
subroutine 4 20 20.0
pod 0 4 0.0
total 16 89 17.9


line stmt bran cond sub pod time code
1             #############################################################################
2             ## Name: stderr.pm
3             ## Purpose: Safe::World::stderr
4             ## Author: Graciliano M. P.
5             ## Modified by:
6             ## Created: 08/09/2003
7             ## RCS-ID:
8             ## Copyright: (c) 2003 Graciliano M. P.
9             ## Licence: This program is free software; you can redistribute it and/or
10             ## modify it under the same terms as Perl itself
11             #############################################################################
12              
13             package Safe::World::stderr ;
14              
15 1     1   5 use strict qw(vars);
  1         3  
  1         32  
16              
17 1     1   4 use vars qw($VERSION @ISA) ;
  1         2  
  1         59  
18             $VERSION = '0.02' ;
19              
20 1     1   5 no warnings ;
  1         2  
  1         30  
21              
22             ##########
23             # SCOPES #
24             ##########
25              
26 1     1   5 use vars qw($Safe_World_NOW) ;
  1         1  
  1         610  
27            
28             *Safe_World_NOW = \$Safe::World::NOW ;
29              
30             #########
31             # BLOCK #
32             #########
33              
34             sub block {
35 0     0 0   my $this = shift ;
36 0           $this->{BLOCKED} = 1 ;
37             }
38              
39             ###########
40             # UNBLOCK #
41             ###########
42              
43             sub unblock {
44 0     0 0   my $this = shift ;
45 0           $this->{BLOCKED} = undef ;
46             }
47              
48             #########
49             # PRINT #
50             #########
51              
52 0     0 0   sub print { &PRINT ;}
53              
54             ################
55             # PRINT_STDERR #
56             ################
57              
58             sub print_stderr {
59 0     0 0   my $this = shift ;
60 0           my $stderr = $this->{STDERR} ;
61            
62 0           $this->{LAST_ERROR} = $_[0] ;
63            
64 0 0         return if $this->{BLOCKED} ;
65            
66 0 0         if ( ref($stderr) eq 'SCALAR' ) { $$stderr .= $_[0] ;}
  0 0          
67             elsif ( ref($stderr) eq 'CODE' ) {
68 0           &$stderr($Safe_World_NOW , $_[0]) ;
69             }
70             else {
71 0           my $sel = \*main::STDERR ;
72 0 0         *main::STDERR = $Safe_World_NOW->{SELECT}{PREVSTDERR} if $Safe_World_NOW->{SELECT}{PREVSTDERR} ;
73 0           print $stderr $_[0] ;
74 0 0         *main::STDERR = $sel if $Safe_World_NOW->{SELECT}{PREVSTDERR} ;
75             }
76              
77 0           return 1 ;
78             }
79              
80             #############
81             # TIEHANDLE #
82             #############
83              
84             sub TIEHANDLE {
85 0     0     my $class = shift ;
86 0           my ($root , $stderr) = @_ ;
87              
88 0           my $this = {
89             ROOT => $root ,
90             STDERR => $stderr ,
91             } ;
92              
93 0           bless($this , $class) ;
94 0           return( $this ) ;
95             }
96              
97             sub PRINT {
98 0     0     my $this = shift ;
99 0           $this->print_stderr( join("", (@_[0..$#_])) ) ;
100 0           return 1 ;
101             }
102              
103 0     0     sub PRINTF { &PRINT($_[0],sprintf($_[1],@_[2..$#_])) ;}
104              
105 0     0     sub READ {}
106 0     0     sub READLINE {}
107 0     0     sub GETC {}
108 0     0     sub WRITE {}
109              
110 0     0     sub FILENO {}
111              
112 0     0     sub CLOSE {}
113              
114             sub STORE {
115 0     0     my $this = shift ;
116 0           my $stdout = shift ;
117 0 0         if ( !ref($stdout) ) {
118 0           $stdout =~ s/^\*// ;
119 0           $stdout = \*{$stdout} ;
  0            
120             }
121 0           $this->{STDOUT} = $stdout ;
122             }
123              
124 0     0     sub FETCH {}
125              
126 0     0     sub DESTROY {}
127              
128             #######
129             # END #
130             #######
131              
132             1;
133              
134