[libio-all-perl] 13/14: ...
Axel Beckert
abe at deuxchevaux.org
Sun Apr 26 22:25:29 UTC 2015
This is an automated email from the git hooks/post-receive script.
abe pushed a commit to tag alt-io-all-new-0.00
in repository libio-all-perl.
commit c6c1c345624bd249df4de62882e675c8c8f56453
Author: Ingy döt Net <ingy at ingy.net>
Date: Wed Jul 25 14:04:27 2012 -0700
...
---
README | 7 ++++---
lib/IO/All.pm | 13 +++++++------
lib/IO/All/File.pm | 16 ++++++++++++++++
lib/IO/All/Filesys.pm | 2 +-
lib/IO/All/{Node.pm => IO.pm} | 4 ++--
lib/IO/All/OO.pm | 2 ++
t/file.t | 10 ++++++++++
t/hai.txt | 1 +
8 files changed, 43 insertions(+), 12 deletions(-)
diff --git a/README b/README
index 8cfd5b6..53fca74 100644
--- a/README
+++ b/README
@@ -47,7 +47,7 @@ Basic Principles of how IO::All should work
* IO::All needs to be completely and consistently extensible
* The extensions that ship with IO-All should be the same as third party
extensions
- * Extensions register capabilities with IO::All (tied to a scope)
+ * Plugins register capabilities with IO::All (tied to a scope)
* IO::All operations can be strict or loose. Strict always throws errors on
any possible error condition. Strict or loose should be determined by the
presence of `use strict` in the scope (possibly).
@@ -55,7 +55,7 @@ Basic Principles of how IO::All should work
is loved by some and hated by others. It should probably be off by default
for 2.0.
-IO::All Extensions
+IO::All Plugins
Currently the extension API is fairly muddy. I would like the new API to
require something like this:
@@ -76,11 +76,12 @@ IO::All Extensions
use IO::All -none;
- Extensions can register 2 things:
+ Plugins can register 2 things:
1. Register a method (or methods) that will force a rebless in that class.
2. Register a regexp (or function) that will cause a rebless when the input
to io(...) matches.
+ 3. Register overloads that the plugin responds to.
These things are register according to the scope of the IO::All, so that
the `io` function will do the right things.
diff --git a/lib/IO/All.pm b/lib/IO/All.pm
index 72cbd07..0e48c52 100644
--- a/lib/IO/All.pm
+++ b/lib/IO/All.pm
@@ -57,10 +57,9 @@ sub make_constructor {
or $self->throw("Can't require $plugin_class: $@");
$self->register_methods($plugin_class);
$self->register_overloads($plugin_class);
- if (ref($self) eq $class) {
- if ($plugin_class->can_upgrade($self)) {
- $self->rebless($plugin_class);
- }
+ if ($plugin_class->can_upgrade($self)) {
+ $self->rebless($plugin_class);
+ last;
}
}
return $self;
@@ -80,7 +79,7 @@ sub parse_args {
unless $key =~ $arg_key_pattern;
my $arg = [$1];
push @$arg, shift(@_)
- while @_ and $_[0] !~ $arg_key_pattern;
+ while @_ and $_[0] !~ $arg_key_pattern;
push @$args, $arg;
}
return $args;
@@ -108,7 +107,9 @@ sub AUTOLOAD {
my $self = shift;
(my $method = $IO::All::AUTOLOAD) =~ s/.*:://;
my $plugin_class = $self->methods->{$method}
- or $self->throw("Can't locate object method '$method'");
+ or $self->throw(
+ "Can't locate object method '$method' for '$self' object"
+ );
$self->rebless($plugin_class);
$self->$method(@_);
}
diff --git a/lib/IO/All/File.pm b/lib/IO/All/File.pm
index 57437c6..060b691 100644
--- a/lib/IO/All/File.pm
+++ b/lib/IO/All/File.pm
@@ -11,6 +11,8 @@ extends 'IO::All::Filesys';
option 'utf8';
+has handle => ();
+
# Upgrade from IO::All to IO::All::Dir
use constant upgrade_methods => [qw(file print)];
@@ -33,6 +35,20 @@ sub file {
return $self;
}
+sub open {
+ my $self = shift;
+ my $fh;
+ open $fh, '<', $self->name;
+ $self->handle($fh);
+ return $self;
+}
+
+sub all {
+ my $self = shift;
+ my $fh = $self->open->handle;
+ return do { local $/; <$fh> }
+}
+
sub print {
my $self = shift;
CORE::print(@_);
diff --git a/lib/IO/All/Filesys.pm b/lib/IO/All/Filesys.pm
index 119da43..15674d5 100644
--- a/lib/IO/All/Filesys.pm
+++ b/lib/IO/All/Filesys.pm
@@ -7,7 +7,7 @@
package IO::All::Filesys;
use IO::All::OO;
-extends 'IO::All::Node';
+extends 'IO::All::IO';
has name => ();
option overload => ();
diff --git a/lib/IO/All/Node.pm b/lib/IO/All/IO.pm
similarity index 87%
rename from lib/IO/All/Node.pm
rename to lib/IO/All/IO.pm
index ad818c7..46a43ea 100644
--- a/lib/IO/All/Node.pm
+++ b/lib/IO/All/IO.pm
@@ -1,11 +1,11 @@
##
-# name: IO::All::Node
+# name: IO::All::IO
# author: Ingy döt Net
# abstract: Base Class for Various IO::All Objects
# license: perl
# copyright: 2012
-package IO::All::Node;
+package IO::All::IO;
use IO::All::OO;
has upgrade_methods => ( default => sub { [] } );
diff --git a/lib/IO/All/OO.pm b/lib/IO/All/OO.pm
index 882cdad..f9c4b51 100644
--- a/lib/IO/All/OO.pm
+++ b/lib/IO/All/OO.pm
@@ -63,6 +63,8 @@ sub field {
};
}
+package IO::All::OO::Object;
+
sub throw {
my $self = shift;
require Carp;
diff --git a/t/file.t b/t/file.t
new file mode 100644
index 0000000..6300e54
--- /dev/null
+++ b/t/file.t
@@ -0,0 +1,10 @@
+use Test::More tests => 3;
+
+use IO::All;
+
+is io('t/hai.txt')->all, "O HAI\n",
+ 'Implicit file works';
+is io->file('t/hai.txt')->all, "O HAI\n",
+ 'Explicit file works';
+is io('t/hai.txt')->file->all, "O HAI\n",
+ 'Implicit/Explicit file works';
diff --git a/t/hai.txt b/t/hai.txt
new file mode 100644
index 0000000..d9fb8fe
--- /dev/null
+++ b/t/hai.txt
@@ -0,0 +1 @@
+O HAI
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libio-all-perl.git
More information about the Pkg-perl-cvs-commits
mailing list