Permalink
Browse files

samples cleanup and intermezzo patches

  • Loading branch information...
1 parent f5b5e07 commit 0e4513f6a9c3d5825cc45bb07792982794d961a5 @rcaputo committed Nov 12, 2000
View
21 Changes
@@ -61,17 +61,32 @@ Version numbers have four fields: X.YYZZAA
`----------------------------------------------------
-0.1110 2000.??.??
+0.1110 2000.11.11
-----------------
-Clean-up release, mainly to get ready for 0.12.
-
Added ARG1 to Wheel::ListenAccept's AcceptState parameter. This
contains the accept() call's return address.
Cleaned up and tested the samples. They all should work with the
latest version of POE.
+The InterMezzo team contributed &POE::Kernel::select_pause_read() and
+&POE::Kernel::select_resume_read(). Added and documented them.
+
+The InterMezzo team contributed &POE::Kernel::get_active_session() and
+&POE::Session::get_heap(). Added and documented them.
+
+(!!!) The InterMezzo team suggested replacing exists() parameter
+checks with defined(). The change will make undefined parameters (in
+the form C<Parameter => undef>) look like they were not passed. This
+simplifies code in some cases while not complicating it anywhere. In
+most cases, this change should not alter the way existing code
+behaves. It's sweeping enough, however, than I've marked it
+compatibility-breaking just in case. Modules affected: FollowTail.pm;
+ListenAccept.pm; ReadWrite.pm; SocketFactory.pm; Block.pm; Line.pm;
+SysRW.pm. Note, however, than undefined InputLiteral in the Line
+filter has a special meaning, so its exists() check was retained.
+
0.1109 2000.10.30
-----------------
View
@@ -32,7 +32,7 @@ sub new {
croak "$type requires an even number of parameters, if any";
}
my %args = @_;
- if (exists $args{BlockSize}) {
+ if (defined $args{BlockSize}) {
$self->[BLOCK_SIZE] = delete $args{BlockSize};
croak "$type BlockSize must be greater than 0"
if ($self->[BLOCK_SIZE]<1);
View
@@ -17,7 +17,7 @@ sub new {
my %params = @_;
my $block_size = $params{BlockSize};
- if (exists($params{BlockSize}) and defined($block_size)) {
+ if (defined($params{BlockSize}) and defined($block_size)) {
croak "$type doesn't support zero or negative block sizes"
if $block_size < 1;
}
View
@@ -25,22 +25,22 @@ sub new {
my %params = @_;
croak "$type cannot have both Regexp and Literal line endings"
- if exists $params{Regexp} and exists $params{Literal};
+ if defined $params{Regexp} and defined $params{Literal};
my ($input_regexp, $output_literal);
my $autodetect = AUTO_STATE_DONE;
# Literal newline for both incoming and outgoing. Every other known
# parameter conflicts with this one.
- if (exists $params{Literal}) {
+ if (defined $params{Literal}) {
croak "Literal must be defined and have a nonzero length"
unless defined($params{Literal}) and length($params{Literal});
$input_regexp = quotemeta $params{Literal};
$output_literal = $params{Literal};
croak "$type cannot have Literal with any other parameter"
- if ( exists $params{InputLiteral } or
- exists $params{InputRegexp } or
- exists $params{OutputLiteral}
+ if ( exists $params{InputLiteral} or # undef means something
+ defined $params{InputRegexp} or
+ defined $params{OutputLiteral}
);
}
@@ -63,18 +63,18 @@ sub new {
}
croak "$type cannot have both InputLiteral and InputRegexp"
- if exists $params{InputRegexp};
+ if defined $params{InputRegexp};
}
- elsif (exists $params{InputRegexp}) {
+ elsif (defined $params{InputRegexp}) {
$input_regexp = $params{InputRegexp};
croak "$type cannot have both InputLiteral and InputRegexp"
- if exists $params{InputLiteral};
+ if defined $params{InputLiteral};
}
else {
$input_regexp = "(\\x0D\\x0A?|\\x0A\\x0D?)";
}
- if (exists $params{OutputLiteral}) {
+ if (defined $params{OutputLiteral}) {
$output_literal = $params{OutputLiteral};
}
else {
View
@@ -528,8 +528,8 @@ sub _poe_signal_handler_pipe {
# SIGCH?LD are normalized to SIGCHLD and include the child process'
# PID and return code. Philip Gwyn rewrote most of the SIGCH?LD code
# for version 0.1006; it got rewritten again while the patches were
-# manually applied. I expect it to be rewritten a few more times to
-# fix Philip's code back the way it ought to be.
+# manually applied. I expect it to be rewritten a few more times as
+# it approaches Philip's original code.
sub _poe_signal_handler_child {
if (defined $_[0]) {
@@ -2039,6 +2039,11 @@ sub assert_gc_refcount {
}
}
+sub get_active_session {
+ my $self = shift;
+ return $self->[KR_ACTIVE_SESSION];
+}
+
#==============================================================================
# EVENTS
#==============================================================================
@@ -2873,6 +2878,84 @@ sub select_resume_write {
return 1;
}
+# Turn off a handle's read vector bit without doing garbage-collection
+# things.
+sub select_pause_read {
+ my ($self, $handle) = @_;
+
+ {% validate_handle $handle, VEC_RD %}
+
+ # Turn off the select vector's read bit for us. We don't do any
+ # housekeeping since we're only pausing the handle. It's assumed
+ # that we'll resume it again at some point.
+
+ vec($self->[KR_VECTORS]->[VEC_RD], fileno($handle), 1) = 0;
+
+ if (POE_USES_GTK) { # include
+
+ my $kr_handle = $self->[KR_HANDLES]->{$handle};
+
+ Gtk::Gdk->input_remove( $kr_handle->[HND_WATCHERS]->[VEC_RD] );
+ $kr_handle->[HND_WATCHERS]->[VEC_RD] = undef;
+
+ } elsif (POE_USES_TK) { # include
+
+ $poe_main_window->fileevent
+ ( $handle,
+ 'readable',
+ ''
+ );
+
+ } elsif (POE_USES_EVENT) { # include
+
+ $self->[KR_HANDLES]->{$handle}->[HND_WATCHERS]->[VEC_RD]->stop();
+
+ } # include
+
+ return 0;
+}
+
+# Turn on a handle's read vector bit without doing garbage-collection
+# things.
+sub select_resume_read {
+ my ($self, $handle) = @_;
+
+ {% validate_handle $handle, VEC_RD %}
+
+ # Turn the select vector's read bit back on. Resume whatever
+ # watcher whichever event loop needs.
+
+ vec($self->[KR_VECTORS]->[VEC_RD], fileno($handle), 1) = 1;
+
+ if (POE_USES_GTK) { # include
+
+ my $kr_handle = $self->[KR_HANDLES]->{$handle};
+
+ confess "resuming unpaused handle"
+ if defined $self->[KR_HANDLES]->{$handle}->[HND_WATCHERS]->[VEC_RD];
+
+ $self->[KR_HANDLES]->{$handle}->[HND_WATCHERS]->[VEC_RD] =
+ Gtk::Gdk->input_add( fileno($handle), 'read',
+ \&_gtk_select_read_callback, $handle
+ );
+
+ } elsif (POE_USES_TK) { # include
+
+ $poe_main_window->fileevent
+ ( $handle,
+ 'readable',
+ [ \&_tk_select_callback, $handle, VEC_RD ],
+ );
+
+ } elsif (POE_USES_EVENT) { # include
+
+ $self->[KR_HANDLES]->{$handle}->[HND_WATCHERS]->[VEC_RD]->start();
+
+ } # include
+
+ return 1;
+}
+
#==============================================================================
# ALIASES
#==============================================================================
@@ -3246,6 +3329,11 @@ External reference count methods:
# Decrement a session's external reference count.
$kernel->refcount_decrement( $session_id, $refcount_name );
+Kernel data accessors:
+
+ # Return a reference to the currently active session, or undef.
+ $session = $kernel->get_active_session();
+
Exported symbols:
# A reference to the global POE::Kernel instance.
@@ -4176,6 +4264,21 @@ did) exist.
=back
+=head2 Kernel Data Accessors
+
+These functions provide a consistent interface to the Kernel's
+internal data.
+
+=over 2
+
+=item get_active_session
+
+This function returns a reference to the session which is currently
+being invoked by the Kernel. It returns undef if no session is being
+invoked at the time.
+
+=back
+
=head1 SEE ALSO
The POE manpages contains holistic POE information.
View
@@ -645,6 +645,15 @@ sub option {
}
}
+# Fetch the session's heap. In rare cases, libraries may need to
+# break encapsulation this way, probably also using
+# $kernel->get_current_session as an accessory to the crime.
+
+sub get_heap {
+ my $self = shift;
+ return $self->[SE_NAMESPACE];
+}
+
#------------------------------------------------------------------------------
# Create an anonymous sub that, when called, posts an event back to a
# session. This is highly experimental code to support Tk widgets and
@@ -785,6 +794,9 @@ Other methods:
# Retrieve a session's unique identifier.
$session_id = $session->ID;
+ # Retrieve a reference to the session's heap.
+ $session_heap = $session->get_heap;
+
# Set or clear session options.
$session->option( trace => 1, default => 1 );
$session->option( trace );
@@ -1428,6 +1440,38 @@ Event->flawor gives its callback.
desc => 'post ev_flavor when Event->flavor occurs',
);
+=item get_heap
+
+Returns a reference to the session's heap. This is the same value
+that's passed to the session in $_[HEAP]. The difference is that this
+method may be used by functions which are expected to be called by a
+session but which don't want the heap to be passed to them. In those
+cases, the function would use $poe_kernel->get_active_session() first
+to determine the session context in which it was called:
+
+ sub use_a_wheel {
+ my @stuff_to_put = @_;
+ $poe_kernel->get_active_session()->heap()->{wheel}->put(@stuff_to_put);
+ }
+
+It probably is more efficient for sessions to pass $_[HEAP] along:
+
+ sub use_a_wheel {
+ my ($heap, @stuff_to_put) = @_;
+ $heap->{wheel}->put(@stuff_to_put);
+ }
+
+Or even:
+
+ sub use_a_wheel {
+ my $heap = shift;
+ $heap->{wheel}->put(@_);
+ }
+
+Although if you expect to have a lot of calls to &put_a_wheel() in
+your program, you may want to optimize for programmer efficiency by
+using the first form.
+
=back
=head1 SEE ALSO
@@ -38,21 +38,19 @@ sub new {
croak "$type requires a working Kernel"
unless (defined $poe_kernel);
- croak "Handle required" unless (exists $params{'Handle'});
- croak "Driver required" unless (exists $params{'Driver'});
- croak "Filter required" unless (exists $params{'Filter'});
- croak "InputState required" unless (exists $params{'InputState'});
+ croak "Handle required" unless defined $params{'Handle'};
+ croak "Driver required" unless defined $params{'Driver'};
+ croak "Filter required" unless defined $params{'Filter'};
+ croak "InputState required" unless defined$params{'InputState'};
my ($handle, $driver, $filter) = @params{ qw(Handle Driver Filter) };
- my $poll_interval = ( (exists $params{'PollInterval'})
+ my $poll_interval = ( (defined $params{'PollInterval'})
? $params{'PollInterval'}
: 1
);
- my $seek_back = ( ( exists($params{SeekBack})
- and defined($params{SeekBack})
- )
+ my $seek_back = ( (defined $params{SeekBack})
? $params{SeekBack}
: 4096
);
@@ -93,7 +91,7 @@ sub new {
};
# Discard partial input chunks unless a SeekBack was specified.
- unless (exists $params{SeekBack}) {
+ unless (defined $params{SeekBack}) {
while (defined(my $raw_input = $driver->get($handle))) {
# Skip out if there's no more input.
last unless @$raw_input;
@@ -22,8 +22,8 @@ sub new {
croak "$type requires a working Kernel" unless defined $poe_kernel;
- croak "Handle required" unless exists $params{Handle};
- croak "AcceptState required" unless exists $params{AcceptState};
+ croak "Handle required" unless defined $params{Handle};
+ croak "AcceptState required" unless defined $params{AcceptState};
my $self = bless { handle => $params{Handle},
event_accept => $params{AcceptState},
Oops, something went wrong.

0 comments on commit 0e4513f

Please sign in to comment.