Skip to content

Commit

Permalink
Propagate the POE::Kernel TRACE and ASSERT constants into any other
Browse files Browse the repository at this point in the history
package that is interested in them.  This passes environment variables
down into other packages.
  • Loading branch information
rcaputo committed Nov 2, 2003
1 parent 3321ff1 commit 8ae8b71
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
8 changes: 5 additions & 3 deletions lib/POE.pm
Expand Up @@ -18,9 +18,6 @@ sub import {
croak "POE::Session and POE::NFA export conflicting constants"
if grep(/^(Session|NFA)$/, @sessions) > 1;

# Add Kernel back it, whether anybody wanted it or not.
unshift @modules, 'Kernel';

# If a session was specified, use that. Otherwise use Session.
if (@sessions) {
unshift @modules, @sessions;
Expand All @@ -29,6 +26,11 @@ sub import {
unshift @modules, 'Session';
}

# Add Kernel back in, whether anybody wanted it or not. Ensure that
# it comes before any sessions, since the sessions need to refer to
# constants defined in Kernel's namespace.
unshift @modules, 'Kernel';

my $package = (caller())[0];

my @failed;
Expand Down
12 changes: 11 additions & 1 deletion lib/POE/NFA.pm
Expand Up @@ -44,8 +44,18 @@ sub STACK_EVENT () { 1 }
sub define_trace {
no strict 'refs';
foreach my $name (@_) {
unless (defined *{"TRACE_$name"}{CODE}) {
next if defined *{"TRACE_$name"}{CODE};
if (defined *{"POE::Kernel::TRACE_$name"}{CODE}) {
eval(
"sub TRACE_$name () { " .
*{"POE::Kernel::TRACE_$name"}{CODE}->() .
"}"
);
die if $@;
}
else {
eval "sub TRACE_$name () { TRACE_DEFAULT }";
die if $@;
}
}
}
Expand Down
28 changes: 26 additions & 2 deletions lib/POE/Session.pm
Expand Up @@ -40,7 +40,19 @@ sub define_assert {
no strict 'refs';
foreach my $name (@_) {
next if defined *{"ASSERT_$name"}{CODE};
eval "sub ASSERT_$name () { ASSERT_DEFAULT }";
no warnings;
if (defined *{"POE::Kernel::ASSERT_$name"}{CODE}) {
eval(
"sub ASSERT_$name () { " .
*{"POE::Kernel::ASSERT_$name"}{CODE}->() .
"}"
);
die if $@;
}
else {
eval "sub ASSERT_$name () { ASSERT_DEFAULT }";
die if $@;
}
}
}

Expand All @@ -49,7 +61,19 @@ sub define_trace {
no strict 'refs';
foreach my $name (@_) {
next if defined *{"TRACE_$name"}{CODE};
eval "sub TRACE_$name () { TRACE_DEFAULT }";
no warnings;
if (defined *{"POE::Kernel::TRACE_$name"}{CODE}) {
eval(
"sub TRACE_$name () { " .
*{"POE::Kernel::TRACE_$name"}{CODE}->() .
"}"
);
die if $@;
}
else {
eval "sub TRACE_$name () { TRACE_DEFAULT }";
die if $@;
}
}
}

Expand Down

0 comments on commit 8ae8b71

Please sign in to comment.