# Copyright (c) 1999-2009 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: Action.pm,v 2.9 2010/12/24 13:42:39 nagler Exp $ package Bivio::Biz::Action; use strict; use Bivio::Base 'Collection.Attributes'; our($VERSION) = sprintf('%d.%02d', q$Revision: 2.9 $ =~ /\d+/g); my($_CLASS_TO_SINGLETON) = {}; sub CLASSLOADER_MAP_NAME { return 'Action'; } sub delete_from_request { my($proto, $req) = @_; return $proto->delete_from_req($req); } sub execute { my($proto, $req, $class) = @_; die("abstract method") unless $class; return $proto->get_instance($class)->execute($req); } sub get_instance { my($proto, $class) = @_; $class = defined($class) ? b_use('Action', ref($class) ? ref($class) : $class) : ref($proto) ? ref($proto) : $proto; return $_CLASS_TO_SINGLETON->{$class} ||= $class->new->set_read_only; } sub get_request { my($self) = @_; return ref($self) && $self->unsafe_get('req') || shift->SUPER::get_request(@_); } sub new { my(undef, $req) = @_; return shift->SUPER::new->put_on_request(@_) if b_use('Agent.Request')->is_blessed($req); return shift->SUPER::new(@_); } sub put_on_request { my($self, $req, $durable) = @_; b_die($self, ': may not put singleton on request') if $self->get_instance eq $self; $self->put(req => $req); return $self->put_on_req($req, $durable); } 1;