Permalink
Browse files

Remove the POE::Loop modules from the modules that need to be loaded

seperately, as they're being passed to POE::Kernel. Also die when
attempting to load more than one Loop. And add some tests to make sure
it works like we want to.
  • Loading branch information...
1 parent cb72f14 commit 5d1b97a43c0e51b923bb5c993256d15a9bdfcb67 Martijn van Beers committed Oct 13, 2004
Showing with 45 additions and 4 deletions.
  1. +5 −3 lib/POE.pm
  2. +3 −0 lib/POE/Kernel.pm
  3. +8 −1 tests/10_units/03_base/01_poe.t
  4. +29 −0 tests/10_units/03_base/14_kernel.t
View
@@ -13,10 +13,12 @@ $REVISION = do {my@r=(q$Revision$=~/\d+/g);sprintf"%d."."%04d"x$#r,@r};
sub import {
my $self = shift;
- my @loops = map { s/^Loop\:\:// } grep(/^Loop\:\:/, @_);
+ my @loops = grep(/^Loop\:\:/, @_);
my @sessions = grep(/^(Session|NFA)$/, @_);
- my @modules = grep(!/^(Kernel|Session|NFA)$/, @_);
+ my @modules = grep(!/^(Kernel|Session|NFA|Loop)$/, @_);
+ croak "can't use multiple event loops at once"
+ if (@loops > 1);
croak "POE::Session and POE::NFA export conflicting constants"
if grep(/^(Session|NFA)$/, @sessions) > 1;
@@ -38,7 +40,7 @@ sub import {
{
my $loop = "";
if (@loops) {
- $loop = '{ loop => [ "' . join("', '", @loops) . "' ] }";
+ $loop = "{ loop => '" . shift (@loops) . "' }";
}
my $code = "package $package; use POE::Kernel $loop;";
# warn $code;
View
@@ -26,6 +26,9 @@ sub import {
my ($class, $args) = @_;
my $package = caller();
+ croak "POE::Kernel expects its arguments in a hash ref"
+ if ($args && ref($args) ne 'HASH');
+
{
no strict 'refs';
*{ $package . '::poe_kernel' } = \$poe_kernel;
@@ -2,7 +2,7 @@
use strict;
-use Test::More tests => 4;
+use Test::More tests => 5;
BEGIN { eval "use POE"; ok(!$@, "you just saved a kitten"); }
@@ -27,4 +27,11 @@ ok(
$@ && $@ =~ /could not import qw\(nonexistent\)/,
"don't import nonexistent modules"
);
+
+eval {POE->import( qw( Loop::Foo Loop::Bar) ) };
+ok(
+ $@ && $@ =~ /multiple event loops/,
+ "don't load more than one event loop"
+);
+
exit 0;
@@ -0,0 +1,29 @@
+#!/usr/bin/perl -w
+
+use strict;
+
+use Test::More tests => 4;
+
+BEGIN { eval "use POE::Kernel"; ok(!$@, "kernel loads"); }
+
+# Start with errors.
+
+eval { POE::Kernel->import( 'foo' ) };
+ok(
+ $@ && $@ =~ /expects its arguments/,
+ "fails without a hash ref"
+);
+
+eval { POE::Kernel->import( { foo => "bar" } ) };
+ok(
+ $@ && $@ =~ /import arguments/,
+ "fails with bogus hash ref"
+);
+
+eval { POE::Kernel->import( { loop => "Loop::Select" } ) };
+ok(
+ !$@,
+ "specifying which loop to load works"
+);
+
+exit 0;

0 comments on commit 5d1b97a

Please sign in to comment.