Data.pm 649 B

123456789101112131415161718192021222324252627282930313233
  1. package Trog::Data;
  2. use strict;
  3. use warnings;
  4. no warnings 'experimental';
  5. use feature qw{signatures state};
  6. #It's just a factory
  7. =head1 Trog::Data
  8. This is a data model factory.
  9. =head2 Trog::Data->new(Trog::Config) = $handle
  10. Returns a new Trog::Data::* class appropriate to what is configured in the Trog::Config object passed.
  11. =cut
  12. sub new ( $class, $config ) {
  13. state $datamodule;
  14. return $datamodule if $datamodule;
  15. my $module = "Trog::Data::" . $config->param('general.data_model');
  16. my $req = $module;
  17. $req =~ s/::/\//g;
  18. require "$req.pm";
  19. $datamodule = $module->new($config);
  20. return $datamodule;
  21. }
  22. 1;