Changeset 230
- Timestamp:
- 04/12/07 18:08:26 (2 years ago)
- Files:
-
- trunk/src/ingy/IO-All/Changes (modified) (1 diff)
- trunk/src/ingy/IO-All/MANIFEST (modified) (2 diffs)
- trunk/src/ingy/IO-All/META.yml (modified) (1 diff)
- trunk/src/ingy/IO-All/README (modified) (5 diffs)
- trunk/src/ingy/IO-All/lib/IO/All.pm (modified) (4 diffs)
- trunk/src/ingy/IO-All/lib/IO/All.pod (modified) (5 diffs)
- trunk/src/ingy/IO-All/lib/IO/All/Base.pm (modified) (1 diff)
- trunk/src/ingy/IO-All/t/encoding.t (added)
- trunk/src/ingy/IO-All/t/text.big5 (added)
- trunk/src/ingy/IO-All/t/text.utf8 (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/src/ingy/IO-All/Changes
r225 r230 1 --- 2 version: 0.38 3 date: Mon Apr 9 10:52:44 JST 2007 4 changes: 5 - Add generic encoding, instead of just utf8. 1 6 --- 2 7 version: 0.37 trunk/src/ingy/IO-All/MANIFEST
r225 r230 40 40 t/devnull.t 41 41 t/empty.t 42 t/encoding.t 42 43 t/error1.t 43 44 t/file_spec.t … … 79 80 t/synopsis3.t 80 81 t/synopsis5.t 82 t/text.big5 83 t/text.utf8 81 84 t/tie.t 82 85 t/tie_file.t trunk/src/ingy/IO-All/META.yml
r225 r230 5 5 generated_by: hand 6 6 distribution_type: module 7 version: 0.3 77 version: 0.38 8 8 name: IO-All 9 9 author: Ingy döt Net <ingy@cpan.org> trunk/src/ingy/IO-All/README
r225 r230 32 32 $contents = io('file.txt')->utf8->all; # Turn on utf8 33 33 use IO::All -utf8; # Turn on utf8 for all io 34 $contents = io('file.txt')->all; # by default in this package. 35 36 # General Encoding Support 37 $contents = io('file.txt')->encoding('big5')->all; 38 use IO::All -encoding => 'big5'; # Turn on big5 for all io 34 39 $contents = io('file.txt')->all; # by default in this package. 35 40 … … 167 172 You can also pass global flags like this: 168 173 169 use IO::All -strict - utf8-foobar;174 use IO::All -strict -encoding => 'big5', -foobar; 170 175 171 176 Which automatically makes those method calls on every new IO object. In … … 176 181 becomes this: 177 182 178 my $io = io('lalala.txt')->strict-> utf8->foobar;183 my $io = io('lalala.txt')->strict->encoding('big5')->foobar; 179 184 180 185 METHOD ROLE CALL … … 189 194 "chdir", "chomp", "clear", "close", "confess", "content", "ctime", 190 195 "curdir", "dbm", "deep", "device", "device_id", "devnull", "dir", 191 "domain", "empty", "e of", "errors", "file", "filename", "fileno",192 "file path", "filter", "fork", "from", "ftp", "get", "getc", "getline",193 "getline s", "gid", "handle", "head", "http", "https", "inode",194 "i o_handle", "is_absolute", "is_dir", "is_dbm", "is_executable",195 "is_ file", "is_link", "is_mldbm", "is_open", "is_pipe", "is_readable",196 "is_ socket", "is_stdio", "is_string", "is_temp", "is_writable", "join",197 " length", "link", "lock", "mailer", "mailto", "mkdir", "mkpath",198 "m ldbm", "mode", "modes", "mtime", "name", "new", "next", "nlink",199 " open", "password", "path", "pathname", "perms", "pipe", "port",200 "p rint", "printf", "println", "put", "rdonly", "rdwr", "read",201 "read dir", "readlink", "recv", "rel2abs", "relative", "rename",196 "domain", "empty", "encoding", "eof", "errors", "file", "filename", 197 "fileno", "filepath", "filter", "fork", "from", "ftp", "get", "getc", 198 "getline", "getlines", "gid", "handle", "head", "http", "https", 199 "inode", "io_handle", "is_absolute", "is_dir", "is_dbm", 200 "is_executable", "is_file", "is_link", "is_mldbm", "is_open", "is_pipe", 201 "is_readable", "is_socket", "is_stdio", "is_string", "is_temp", 202 "is_writable", "join", "length", "link", "lock", "mailer", "mailto", 203 "mkdir", "mkpath", "mldbm", "mode", "modes", "mtime", "name", "new", 204 "next", "nlink", "open", "password", "path", "pathname", "perms", 205 "pipe", "port", "print", "printf", "println", "put", "rdonly", "rdwr", 206 "read", "readdir", "readlink", "recv", "rel2abs", "relative", "rename", 202 207 "request", "response", "rmdir", "rmtree", "rootdir", "scalar", "seek", 203 208 "send", "separator", "shutdown", "size", "slurp", "socket", "sort", … … 780 785 Set the domain name or ip address that a socket should use. 781 786 787 * encoding 788 Set the encoding to be used for the PerlIO layer. 789 782 790 * errors 783 791 Use this to set a subroutine reference that gets called when an trunk/src/ingy/IO-All/lib/IO/All.pm
r225 r230 7 7 sub Carp::carp; 8 8 use IO::All::Base -base; 9 our $VERSION = '0.3 7';9 our $VERSION = '0.38'; 10 10 use File::Spec(); 11 11 use Symbol(); … … 360 360 field _binmode => undef; 361 361 field _strict => undef; 362 field _encoding => undef; 362 363 field _utf8 => undef; 363 364 field _handle => undef; … … 688 689 sub utf8 { 689 690 my $self = shift; 690 return $self if $] < 5.008; 691 if ($] < 5.008) { 692 die "IO::All -utf8 not supported on Perl older than 5.8"; 693 } 691 694 CORE::binmode($self->io_handle, ':utf8') 692 695 if $self->is_open; 693 696 $self->_utf8(1); 697 $self->encoding('utf8'); 698 return $self; 699 } 700 701 sub encoding { 702 my $self = shift; 703 my $encoding = shift 704 or die "No encoding value passed to IO::All::encoding"; 705 if ($] < 5.008) { 706 die "IO::All -encoding not supported on Perl older than 5.8"; 707 } 708 CORE::binmode($self->io_handle, ":$encoding") 709 if $self->is_open; 710 $self->_encoding($encoding); 694 711 return $self; 695 712 } … … 762 779 sub set_binmode { 763 780 my $self = shift; 764 CORE::binmode($self->io_handle) 765 if $self->_binary; 766 CORE::binmode($self->io_handle, ":utf8") 767 if $self->_utf8; 768 CORE::binmode($self->io_handle, $self->_binmode) 769 if $self->_binmode; 781 if (my $encoding = $self->_encoding) { 782 CORE::binmode($self->io_handle, ":encoding($encoding)"); 783 } 784 elsif ($self->_binary) { 785 CORE::binmode($self->io_handle); 786 } 787 elsif ($self->_binmode) { 788 CORE::binmode($self->io_handle, $self->_binmode); 789 } 770 790 return $self; 771 791 } trunk/src/ingy/IO-All/lib/IO/All.pod
r225 r230 34 34 $contents = io('file.txt')->utf8->all; # Turn on utf8 35 35 use IO::All -utf8; # Turn on utf8 for all io 36 $contents = io('file.txt')->all; # by default in this package. 37 38 # General Encoding Support 39 $contents = io('file.txt')->encoding('big5')->all; 40 use IO::All -encoding => 'big5'; # Turn on big5 for all io 36 41 $contents = io('file.txt')->all; # by default in this package. 37 42 … … 170 175 You can also pass global flags like this: 171 176 172 use IO::All -strict - utf8-foobar;177 use IO::All -strict -encoding => 'big5', -foobar; 173 178 174 179 Which automatically makes those method calls on every new IO object. In other … … 179 184 becomes this: 180 185 181 my $io = io('lalala.txt')->strict-> utf8->foobar;186 my $io = io('lalala.txt')->strict->encoding('big5')->foobar; 182 187 183 188 =head1 METHOD ROLE CALL … … 194 199 C<close>, C<confess>, C<content>, C<ctime>, C<curdir>, C<dbm>, C<deep>, 195 200 C<device>, C<device_id>, C<devnull>, C<dir>, C<domain>, C<empty>, 196 C<e of>, C<errors>, C<file>, C<filename>, C<fileno>, C<filepath>,197 C<fil ter>, C<fork>, C<from>, C<ftp>, C<get>, C<getc>, C<getline>,198 C<getline s>, C<gid>, C<handle>, C<head>, C<http>, C<https>, C<inode>,199 C<i o_handle>, C<is_absolute>, C<is_dir>, C<is_dbm>, C<is_executable>,200 C<is_ file>, C<is_link>, C<is_mldbm>, C<is_open>, C<is_pipe>,201 C<is_ readable>, C<is_socket>, C<is_stdio>, C<is_string>, C<is_temp>,202 C<is_ writable>, C<join>, C<length>, C<link>, C<lock>, C<mailer>,203 C<mail to>, C<mkdir>, C<mkpath>, C<mldbm>, C<mode>, C<modes>, C<mtime>,204 C< name>, C<new>, C<next>, C<nlink>, C<open>, C<password>, C<path>,205 C<path name>, C<perms>, C<pipe>, C<port>, C<print>, C<printf>,201 C<encoding>, C<eof>, C<errors>, C<file>, C<filename>, C<fileno>, 202 C<filepath>, C<filter>, C<fork>, C<from>, C<ftp>, C<get>, C<getc>, 203 C<getline>, C<getlines>, C<gid>, C<handle>, C<head>, C<http>, C<https>, 204 C<inode>, C<io_handle>, C<is_absolute>, C<is_dir>, C<is_dbm>, 205 C<is_executable>, C<is_file>, C<is_link>, C<is_mldbm>, C<is_open>, 206 C<is_pipe>, C<is_readable>, C<is_socket>, C<is_stdio>, C<is_string>, 207 C<is_temp>, C<is_writable>, C<join>, C<length>, C<link>, C<lock>, 208 C<mailer>, C<mailto>, C<mkdir>, C<mkpath>, C<mldbm>, C<mode>, C<modes>, 209 C<mtime>, C<name>, C<new>, C<next>, C<nlink>, C<open>, C<password>, 210 C<path>, C<pathname>, C<perms>, C<pipe>, C<port>, C<print>, C<printf>, 206 211 C<println>, C<put>, C<rdonly>, C<rdwr>, C<read>, C<readdir>, 207 212 C<readlink>, C<recv>, C<rel2abs>, C<relative>, C<rename>, C<request>, … … 848 853 Set the domain name or ip address that a socket should use. 849 854 855 =item * encoding 856 857 Set the encoding to be used for the PerlIO layer. 858 850 859 =item * errors 851 860 trunk/src/ingy/IO-All/lib/IO/All/Base.pm
r225 r230 29 29 sub generate_constructor { 30 30 my $class = shift; 31 my @flags = grep { s/^-// } @_; 31 my (@flags, %flags, $key); 32 for (@_) { 33 if (s/^-//) { 34 push @flags, $_; 35 $flags{$_} = 1; 36 $key = $_; 37 } 38 else { 39 $flags{$key} = $_ if $key; 40 } 41 } 32 42 my $constructor; 33 43 $constructor = sub { 34 44 my $self = $class->new(@_); 35 for my $flag(@flags) {36 $self->$ flag;45 for (@flags) { 46 $self->$_($flags{$_}); 37 47 } 38 48 $self->constructor($constructor);
