function result = perform_action(target, ext, parameter, context)

% perform_action - perform action on target
% -----------------------------------------
%
% result = perform_action(target, ext, parameter, context)
%
% Input:
% ------
%  target - action target
%  ext - action extension
%  parameter - action parameters
%  context - action context
%
% Output:
% -------
%  result - result of action

%--------------------------------
% Author: Harold Figueroa
%--------------------------------
% $Revision: 1600 $
% $Date: 2005-08-18 17:41:06 -0400 (Thu, 18 Aug 2005) $
%--------------------------------

%--
% try to perform action on target
%--

% NOTE: the line in the 'try' block uses all the input variables

started = clock; 

out = []; error = [];

if isempty(ext.fun.compute)
	
	status = 'undefined';

else

	% TODO: consider how to capture the second output if needed
	
	try
		out = ext.fun.compute(target, parameter, context); status = 'done';
	catch
		error = lasterror; status = 'failed';
	end
	
end

elapsed = etime(clock, started);

%--
% pack action results
%--

result.target = target; 

result.status = status;

result.message = '';

result.error = error;

if ~isempty(error)
	result.message = result.error.message;
end

result.elapsed = elapsed;

result.output = out;
