Author: dylan
Date: 2004-06-28 00:36:03 -0400 (Mon, 28 Jun 2004)
New Revision: 268

Added:
   trunk/main/common/lib/Haver/Callback.pm
Log:
callback abstraction.



Added: trunk/main/common/lib/Haver/Callback.pm
===================================================================
--- trunk/main/common/lib/Haver/Callback.pm     2004-06-28 04:11:58 UTC (rev 
267)
+++ trunk/main/common/lib/Haver/Callback.pm     2004-06-28 04:36:03 UTC (rev 
268)
@@ -0,0 +1,60 @@
+# vim: set ft=perl ts=4 sw=4:
+# Haver::Callback - description
+# 
+# Copyright (C) 2004 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 Haver::Callback;
+use strict;
+use warnings;
+
+use Haver::Preprocessor;
+use base 'Haver::Base';
+
+our $VERSION = '0.01';
+
+sub new {
+       my ($this, $cb, @args) = @_;
+       # ASSERT: ref($cb);
+       my $callback;
+
+       if (ref($cb) eq 'CODE') {
+               $callback = $cb;
+       } elsif (ref($cb) eq 'ARRAY') {
+               @_ = ($this, @$cb, @args);
+               goto &new;
+       } elsif (UNIVERSAL::isa($cb, __PACKAGE__)) {
+               return $cb;
+       } else {
+               my $method = shift @args;
+               $callback = $cb->can($method);
+               unshift(@args, $cb);
+       }
+
+       $this->SUPER::new(
+               callback => $callback,
+               args     => [EMAIL PROTECTED],
+       );
+}
+
+sub call {
+       my ($me, @args) = @_;
+
+       $me->{callback}->(@{ $me->{args} }, @args);
+}
+
+
+1;
+


Reply via email to