Author: bdonlan
Date: 2004-06-11 16:39:32 -0400 (Fri, 11 Jun 2004)
New Revision: 235
Added:
trunk/misc/
trunk/misc/poe-inherit/
trunk/misc/poe-inherit/lib/
trunk/misc/poe-inherit/lib/POE/
trunk/misc/poe-inherit/lib/POE/Session/
trunk/misc/poe-inherit/lib/POE/Session/Inheritable.pm
Modified:
trunk/haver-gtk/lib/Haver/UI/Gtk/Page.pm
Log:
Refactored inheritable session logic out of haver-gtk into a more generic
module
Modified: trunk/haver-gtk/lib/Haver/UI/Gtk/Page.pm
===================================================================
--- trunk/haver-gtk/lib/Haver/UI/Gtk/Page.pm 2004-06-09 21:07:13 UTC (rev
234)
+++ trunk/haver-gtk/lib/Haver/UI/Gtk/Page.pm 2004-06-11 20:39:32 UTC (rev
235)
@@ -20,6 +20,7 @@
package Haver::UI::Gtk::Page;
use warnings;
use strict;
+use base 'POE::Session::Inheritable';
use POE;
use Gtk;
@@ -79,20 +80,14 @@
croak "$package is an abstract base class!" unless $class && $class ne
$package;
- my $self = {
+ my $self = $class->SUPER::new();
+
+ %$self = (
frame => Gtk::Frame->new(),
label => Gtk::Label->new($title),
active => 0,
name => $title,
- };
- bless $self, $class;
- my $oe = $self->_object_states({});
- #print Dumper $oe;
- $self->{session} = POE::Session->create(
- object_states => [
- $self => $self->_object_states({}),
- ], # object_states => [
- )->ID;
+ );
return $self;
}
Copied: trunk/misc/poe-inherit/lib/POE/Session/Inheritable.pm (from rev 234,
trunk/haver-gtk/lib/Haver/UI/Gtk/Page.pm)
===================================================================
--- trunk/haver-gtk/lib/Haver/UI/Gtk/Page.pm 2004-06-09 21:07:13 UTC (rev
234)
+++ trunk/misc/poe-inherit/lib/POE/Session/Inheritable.pm 2004-06-11
20:39:32 UTC (rev 235)
@@ -0,0 +1,141 @@
+# vim: set ft=perl ts=4 sw=4:
+# POE::Session::Inheritable - POE session base class for easy inheritance
+#
+# Copyright (C) 2004 Bryan Donlan, Dylan William Hardison.
+#
+# This module is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This module is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this module; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+package POE::Session::Inheritable;
+use warnings;
+use strict;
+
+use POE;
+use Carp;
+use Data::Dumper;
+
+our $package = __PACKAGE__;
+our $VERSION = 0.01;
+
+=head1 NAME
+
+POE::Session::Inheritable - POE session base class for easy inheritance
+
+=head1 SYNOPSIS
+
+ use base 'POE::Session::Inheritable';
+
+ sub _object_states {
+ my ($self, $ehash) = @_;
+ $ehash = {qw{
+ foo_event foo_handler
+ [...]
+ }, %$ehash};
+ return $self->SUPER::_object_methods($ehash);
+ }
+
+ sub new {
+ my ($class, @args) = @_;
+ my $self = $class->SUPER::new(heap => {foo => 42);
+
+ $poe_kernel->post($self->{session}, 'bar');
+
+ [...]
+
+ return $self;
+ }
+
+=head1 DESCRIPTION
+
+POE::Session::Inheritable is a base class for POE sessions using
object_methods for
+inheritance. Subclasses override _object_states to indicate which object
methods they
+need passed to POE::Session->create()
+
+=head1 METHODS
+
+=cut
+
+### OVERRIDABLE METHODS
+
+=head2 $Z<>object->_object_states($Z<>ehash)
+
+$ehash is a hash reference of superclasses' object methods. This function
should
+add to the hash but not remove any items, pass the new hashref to the
superclass'
+_object_states function, and return the result.
+
+=cut
+
+sub _object_states {
+ my ($self, $ehash) = @_;
+ return $ehash;
+}
+
+=head2 $Z<>package->new(@Z<>poe_args)
+
+Creates a new hashref, and blesses it with $package. Obtains a hash of object
+states from the hashref's ->_object_states(). Passes this to
POE::Session->create,
+along with @poe_args. The ID of the new session is stored in the object under
the
+key 'session'.
+
+=cut
+
+sub new {
+ my ($class, @args) = @_;
+ $class = ref $class || $class;
+
+ croak "$package is an abstract base class!" unless $class && $class ne
$package;
+
+ my $self = {};
+ bless $self, $class;
+ my $oe = $self->_object_states({});
+ #print Dumper $oe;
+ $self->{session} = POE::Session->create(
+ object_states => [
+ $self => $self->_object_states({}),
+ ], # object_states => [
+ )->ID;
+
+ return $self;
+}
+
+=head1 BUGS
+
+None known.
+
+=head1 AUTHOR
+
+Bryan Donlan, E<lt>[EMAIL PROTECTED]<gt> and
+Dylan William Hardison, E<lt>[EMAIL PROTECTED]<gt>
+
+=head1 COPYRIGHT AND LICENSE
+
+Copyright (C) 2004 by Bryan Donlan, Dylan William Hardison
+
+This library is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this module; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+=cut
+