| 1 | package PerlIO::via::QuotedPrint; |
| 2 | |
| 3 | # Set the version info |
| 4 | # Make sure we do things by the book from now on |
| 5 | |
| 6 | $VERSION = '0.06'; |
| 7 | use strict; |
| 8 | |
| 9 | # Make sure the encoding/decoding stuff is available |
| 10 | |
| 11 | use MIME::QuotedPrint (); # no need to pollute this namespace |
| 12 | |
| 13 | # Satisfy -require- |
| 14 | |
| 15 | 1; |
| 16 | |
| 17 | #----------------------------------------------------------------------- |
| 18 | # IN: 1 class to bless with |
| 19 | # 2 mode string (ignored) |
| 20 | # 3 file handle of PerlIO layer below (ignored) |
| 21 | # OUT: 1 blessed object |
| 22 | |
| 23 | sub PUSHED { bless \*PUSHED,$_[0] } #PUSHED |
| 24 | |
| 25 | #----------------------------------------------------------------------- |
| 26 | # IN: 1 instantiated object (ignored) |
| 27 | # 2 handle to read from |
| 28 | # OUT: 1 decoded string |
| 29 | |
| 30 | sub FILL { |
| 31 | |
| 32 | # Read the line from the handle |
| 33 | # Decode if there is something decode and return result or signal eof |
| 34 | |
| 35 | my $line = readline( $_[1] ); |
| 36 | (defined $line) ? MIME::QuotedPrint::decode_qp( $line ) : undef; |
| 37 | } #FILL |
| 38 | |
| 39 | #----------------------------------------------------------------------- |
| 40 | # IN: 1 instantiated object (ignored) |
| 41 | # 2 buffer to be written |
| 42 | # 3 handle to write to |
| 43 | # OUT: 1 number of bytes written |
| 44 | |
| 45 | sub WRITE { |
| 46 | |
| 47 | # Encode whatever needs to be encoded and write to handle: indicate result |
| 48 | |
| 49 | (print {$_[2]} MIME::QuotedPrint::encode_qp($_[1])) ? length($_[1]) : -1; |
| 50 | } #WRITE |
| 51 | |
| 52 | __END__ |
| 53 | |
| 54 | =head1 NAME |
| 55 | |
| 56 | PerlIO::via::QuotedPrint - PerlIO layer for quoted-printable strings |
| 57 | |
| 58 | =head1 SYNOPSIS |
| 59 | |
| 60 | use PerlIO::via::QuotedPrint; |
| 61 | |
| 62 | open( my $in,'<:via(QuotedPrint)','file.qp' ) |
| 63 | or die "Can't open file.qp for reading: $!\n"; |
| 64 | |
| 65 | open( my $out,'>:via(QuotedPrint)','file.qp' ) |
| 66 | or die "Can't open file.qp for writing: $!\n"; |
| 67 | |
| 68 | =head1 DESCRIPTION |
| 69 | |
| 70 | This module implements a PerlIO layer that works on files encoded in the |
| 71 | quoted-printable format. It will decode from quoted-printable while reading |
| 72 | from a handle, and it will encode as quoted-printable while writing to a handle. |
| 73 | |
| 74 | =head1 REQUIRED MODULES |
| 75 | |
| 76 | MIME::QuotedPrint (any) |
| 77 | |
| 78 | =head1 SEE ALSO |
| 79 | |
| 80 | L<PerlIO::via>, L<MIME::QuotedPrint>, L<PerlIO::via::Base64>, |
| 81 | L<PerlIO::via::MD5>, L<PerlIO::via::StripHTML>, L<PerlIO::via::Rotate>. |
| 82 | |
| 83 | =head1 ACKNOWLEDGEMENTS |
| 84 | |
| 85 | Based on example that was initially added to MIME::QuotedPrint.pm for the |
| 86 | 5.8.0 distribution of Perl. |
| 87 | |
| 88 | =head1 COPYRIGHT |
| 89 | |
| 90 | Copyright (c) 2002-2003 Elizabeth Mattijsen. All rights reserved. This |
| 91 | library is free software; you can redistribute it and/or modify it under |
| 92 | the same terms as Perl itself. |
| 93 | |
| 94 | =cut |