File: Native.pm

package info (click to toggle)
liblog-agent-perl 1.005-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 528 kB
  • sloc: perl: 2,352; makefile: 2
file content (107 lines) | stat: -rw-r--r-- 1,882 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
###########################################################################
#
#   Native.pm
#
#   Copyright (C) 1999 Raphael Manfredi.
#   Copyright (C) 2002-2017 Mark Rogaski, mrogaski@cpan.org;
#   all rights reserved.
#
#   See the README file included with the
#   distribution for license information.
#
##########################################################################

use strict;

########################################################################
package Log::Agent::File::Native;

#
# A native Perl filehandle.
#
# I'm no longer using the IO::* hierarchy because it is not adapted
# to what we're trying to achieve here.
#

#
# ->make
#
# Creation routine.
# Turns on autoflush as a side effect.
#
sub make {
	my $class = shift;
	my ($glob) = @_;
	select((select($glob), $| = 1)[0]);		# autoflush turned on
	return bless $glob, $class;
}

#
# ->print
#
# Print to file, propagates print() status.
#
sub print {
	my $glob = shift;
	local $\ = undef;
	return CORE::print $glob @_;
}

#
# ->close
#
# Close file.
#
sub close {
	my $glob = shift;
	CORE::close $glob;
}

#
# ->DESTROY
#
sub DESTROY {
	my $glob = shift;
	CORE::close $glob;
}

1;	# for require
__END__

=head1 NAME

Log::Agent::File::Native - low-overhead IO::File

=head1 SYNOPSIS

 require Log::Agent::File::Native;

 my $fh = Log::Agent::File::Native->make(\*main::STDERR);

=head1 DESCRIPTION

This class is a stripped down implementation of IO::File, to avoid using
the IO::* hierarchy which does not work properly for my simple needs.

=over 4

=item make I<glob>

This is the creation routine. Encapsulates the I<glob> reference so that
we can use object-oriented calls on it.

=item print I<args>

Prints I<args> to the file.

=back

=head1 AUTHOR

Raphael Manfredi F<E<lt>Raphael_Manfredi@pobox.comE<gt>>

=head1 SEE ALSO

Log::Agent::File::Rotate(3), Log::Agent::Driver::File(3).

=cut