in reply to MVC question: way to expose API
every adaptor class is loaded as a component of the frontend base class. at application startup, every component is required and instantiated via new(). The instances are then stored as a class data of the frontend base class, making them some sort of singleton objects.
also looked at DBIx::Class and it uses Class::C3 and Class::C3::Componentised. i suspect that's another way to accomplish my goal.package MyApp::Component; use base qw/Class::Accessor::Fast Class::Data::Inheritable/; 1; package Frontend::Base; use base 'MyApp::Component'; __PACKAGE__->mk_classdata(components); sub load_components { # use module::pluggable # for each adaptor that module::pluggable found # load the adaptor($comp) $class->load_component($comp); } sub load_component { my ($class, $comp) = @_; $class->components->{ $component_name } = $comp->new(); } sub adaptor { my ($class, $model) = @_; return $class->components->{ $component_name }; } 1; package Frontend::Report; use base 'Frontend::Base'; sub do_report { $class->adaptor('Adaptor::Report')->method; } 1;
|
|---|