# Copyright (c) 2008 bivio Software, Inc. All Rights Reserved. # # Visit http://www.bivio.biz for more info. # # This library is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as # published by the Free Software Foundation; either version 2.1 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 # Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public # License along with this library; If not, you may get a copy from: # http://www.opensource.org/licenses/lgpl-license.html # # $Id: Registrar.pm,v 1.4 2009/04/24 12:55:58 nagler Exp $ package Bivio::Biz::Registrar; use strict; use Bivio::Base 'Bivio::UNIVERSAL'; our($VERSION) = sprintf('%d.%02d', q$Revision: 1.4 $ =~ /\d+/g); my($_IDI) = __PACKAGE__->instance_data_index; sub call_fifo { my($self, $method, $args) = @_; my($q) = $self->[$_IDI]; $args ||= []; return [map( !$_->can($method) ? () : $_->$method(ref($args) eq 'CODE' ? @{$args->()} : @$args), @$q, )]; } sub do_filo { my($self, $method, $args) = @_; $args ||= []; foreach my $h (reverse(@{$self->[$_IDI]})) { next unless $h->can($method); my($res) = $h->$method(ref($args) eq 'CODE' ? @{$args->()} : @$args); return $res if defined($res); } return; } sub new { my($self) = shift->SUPER::new; $self->[$_IDI] = []; return $self; } sub push_object { my($self, $object) = @_; $object = b_use($object) unless ref($object); my($q) = $self->[$_IDI]; push(@$q, $object) unless grep($_ eq $object, @$q); return; } 1;