suspend(@results), replacing the normal return statement. =head1 METHODS =over 4 =item $thingie = new Contize($thingie) Takes a $thingie object and continuizes it... we replace it with ourselves and intercept all method calls. =cut # We take over the following elements of the hash: # _child := our child object we've overtaken # _cache := count for how we are doing catch-up wise # _nocache := a list of methods not to cache # _callstack := the current call stack (array) # _callstack_count := the current count of the top callstack item */ class Contize { var $_child, $_child_name; var $_cache = array(); var $_nocache = array(); var $_callstack = array(); var $_callstack_count = array(); function __construct($child) { $this->_child = $child; $this->_child_name = get_class($this->_child); } function nocache($methods) { $_nocache[] = ($methods); } function __sleep() { return( array_keys( get_object_vars( &$this ) ) ); } function __wakeup() { } function __call($name, $args) { if(method_exists($this->_child, $name)) { $this->_callstack[] = $name; $callstack = join(" ", $this->_callstack); $count = ++$this->_callstack_count[$callstack]; $this->_callstack[] = $count; if(preg_grep("/$name/", $this->_nocache)) { // LOOK AT THIS | // LOOK AT THIS | // LOOK AT THIS | // LOOK AT THIS v // How to do argument lists eval("\$val = $this->_child_name::$name(\$args);"); } else { $callstack = join(" ", $this->_callstack); if(isset($this->_cache[$callstack])) { # We've already chached this call, lets just return it $val = $this->_cache[$callstack]; } else { # We've never done this before, lets run it... // LOOK AT THIS | // LOOK AT THIS | // LOOK AT THIS | // LOOK AT THIS v // How to do argument lists eval("\$val = $this->_child_name::$name(\$args);"); $this->_cache[$callstack] = $val; } } array_pop ($this->_callstack); # The num array_pop ($this->_callstack); # and the name return $val; } } // function suspend($ret_val) { function suspend() { $callstack = join(" ", $this->_callstack); $this->_cache[$callstack] = ""; exit; } function __get($name) { return $this->_child->{$name}; } function __set($name, $val) { return $this->_child->{$name} = $val; } function _reset() { $this->_callstack = array(); $this->_callstack_count = array(); } /*=back =head1 SEE ALSO Coro::Cont =head1 AUTHOR Brock Wilcox =head1 COPYRIGHT Copyright (c) 2004 Brock Wilcox . All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1;*/ } // End Contize ?>