RWDE::AbstractFactory - RWDE::AbstractFactory documentation


RWDE documentation Contained in the RWDE distribution.

Index


Code Index:

RWDE::AbstractFactory

Top

Abstract Factory, instantiates and returns any App object

instantiate

Instantiate an instance of the class specified in the parameter

Requires class parameter


RWDE documentation Contained in the RWDE distribution.
package RWDE::AbstractFactory;

use strict;
use warnings;

use Error qw(:try);
use RWDE::Exceptions;

use vars qw($VERSION);
$VERSION = sprintf "%d", q$Revision: 506 $ =~ /(\d+)/;

sub instantiate {
  my ($self, $params) = @_;

  throw RWDE::DevelException({ info => 'AbstractFactory::Parameter error - class not specified' }) unless ($$params{'class'});

  my $proto = $$params{class};

  my $requested_type = ref $proto || $proto;

  delete $$params{class};

  my $library = $requested_type . '.pm';

  $library =~ s/::/\//g;

  require $library;

  return $requested_type->new($params);
}

1;