diff options
author | Dan Kogai <dankogai@dan.co.jp> | 2003-05-24 05:17:16 +0900 |
---|---|---|
committer | Jarkko Hietaniemi <jhi@iki.fi> | 2003-05-23 12:56:23 +0000 |
commit | a0d8a30e4d6cdcb83a19818856ccc52190cdd95f (patch) | |
tree | 1407e4e2e1dca38aa682ac894aa7b740a51edc09 /ext/Encode/lib | |
parent | db0b859feb1075204019fdea30072b46da24e0c5 (diff) | |
download | perl-a0d8a30e4d6cdcb83a19818856ccc52190cdd95f.tar.gz |
Stateful PerlIO implemented [Was: [perl #22261] Was: Unrecognised BOM...]
Message-Id: <1C123D88-8D10-11D7-B277-000393AE4244@dan.co.jp>
p4raw-id: //depot/perl@19593
Diffstat (limited to 'ext/Encode/lib')
-rw-r--r-- | ext/Encode/lib/Encode/Encoding.pm | 32 |
1 files changed, 24 insertions, 8 deletions
diff --git a/ext/Encode/lib/Encode/Encoding.pm b/ext/Encode/lib/Encode/Encoding.pm index 0bb4350a63..3978e9df89 100644 --- a/ext/Encode/lib/Encode/Encoding.pm +++ b/ext/Encode/lib/Encode/Encoding.pm @@ -14,8 +14,10 @@ sub Define Encode::define_encoding($obj, $canonical, @_); } -sub name { return shift->{'Name'} } -sub new_sequence { return $_[0] } +sub name { return shift->{'Name'} } + +sub renew { return $_[0] } +*new_sequence = \&renew; sub needs_lines { 0 }; @@ -24,7 +26,8 @@ sub perlio_ok { return $@ ? 0 : 1; } -# Temporary legacy methods +# (Temporary|legacy) methods + sub toUnicode { shift->decode(@_) } sub fromUnicode { shift->encode(@_) } @@ -160,15 +163,28 @@ Predefined As: MUST return the string representing the canonical name of the encoding. -=item -E<gt>new_sequence +=item -E<gt>renew Predefined As: - sub new_sequence { return $_[0] } + sub renew { return $_[0] } + +This method reconstructs the encoding object if necessary. If you need +to store the state during encoding, this is where you clone your object. +Here is an example: + + sub renew { + my $self = shift; + my $clone = bless { %$self } => ref($self); + $clone->{clone} = 1; # so the caller can see it + return $clone; + } + +Since most encodings are stateless the default behavior is just return +itself as shown above. -This is a placeholder for encodings with state. It should return an -object which implements this interface. All current implementations -return the original object. +PerlIO ALWAYS calls this method to make sure it has its own private +encoding object. =item -E<gt>perlio_ok() |