File: eol.pm

package info (click to toggle)
libperlio-eol-perl 0.13-1
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k, sarge
  • size: 116 kB
  • ctags: 111
  • sloc: perl: 595; ansic: 169; makefile: 53
file content (76 lines) | stat: -rw-r--r-- 2,218 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
package PerlIO::eol;

use 5.007003;
use XSLoader;
use Exporter;

our $VERSION = '0.13';
our @ISA = qw(Exporter);

# symbols to export on request
our @EXPORT_OK = qw(eol_is_mixed CR LF CRLF NATIVE);

XSLoader::load __PACKAGE__, $VERSION;

1;

=head1 NAME

PerlIO::eol - PerlIO layer for normalizing line endings

=head1 VERSION

This document describes version 0.13 of PerlIO::eol, released 
October 18, 2004.

=head1 SYNOPSIS

    binmode STDIN, ":raw:eol(LF)";
    binmode STDOUT, ":raw:eol(CRLF)";
    open FH, "+<:raw:eol(LF-Native)", "file";

    binmode STDOUT, ":raw:eol(CRLF?)"; # warns on mixed newlines
    binmode STDOUT, ":raw:eol(CRLF!)"; # dies on mixed newlines

    use PerlIO::eol qw( eol_is_mixed );
    my $pos = eol_is_mixed( "mixed\nstring\r" );

=head1 DESCRIPTION

This layer normalizes any of C<CR>, C<LF>, C<CRLF> and C<Native> into the
designated line ending.  It works for both input and output handles.

If you specify two different line endings joined by a C<->, it will use the
first one for reading and the second one for writing.  For example, the
C<LF-CRLF> encoding means that all input should be normalized to C<LF>, and
all output should be normalized to C<CRLF>.

By default, data with mixed newlines are normalized silently.  Append a C<!>
to the line ending will raise a fatal exception when mixed newlines are
spotted.  Append a C<?> will raise a warning instead.

It is advised to pop any potential C<:crlf> or encoding layers before this
layer; this is usually done using a C<:raw> prefix.

This module also optionally exports a C<eol_is_mixed> function; it takes a
string and returns the position of the first inconsistent line ending found
in that string, or C<0> if the line endings are consistent.

The C<CR>, C<LF>, <CRLF> and <NATIVE> constants are also exported at request.

=head1 AUTHORS

Autrijus Tang E<lt>autrijus@autrijus.orgE<gt>

Inspired by L<PerlIO::nline> by Ben Morrow, E<lt>PerlIO-eol@morrow.me.ukE<gt>.

=head1 COPYRIGHT

Copyright 2004 by Autrijus Tang E<lt>autrijus@autrijus.orgE<gt>.

This program is free software; you can redistribute it and/or 
modify it under the same terms as Perl itself.

See L<http://www.perl.com/perl/misc/Artistic.html>

=cut