1 package NonameTV
::Factory
;
11 Create other NonameTV objects based on the available configuration.
21 our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS);
25 %EXPORT_TAGS = ( ); # eg: TAG => [ qw!name1 name2! ],
26 @EXPORT_OK = qw
/ CreateAugmenter
27 CreateDataStore CreateDataStoreDummy
28 CreateImporter CreateExporter CreateFileStore
34 use NonameTV
::Config qw
/ReadConfig/;
36 =item CreateAugmenter( $name, $ds )
38 Create an augmenter from the configuration in $conf->{Augmenter}->{$name}
39 and associate it with the NonameTV::DataStore in $ds.
41 Returns the newly created augmenter or dies if creation fails.
46 my( $name, $ds ) = @_;
48 my $conf = ReadConfig
();
50 if( not exists( $conf->{Augmenters
}->{$name} ) ) {
51 print STDERR
"No such augmenter $name\n";
55 my $aug_data = $conf->{Augmenters
}->{$name};
56 $aug_data->{ConfigName
} = $name;
58 my $aug_type = $aug_data->{Type
};
60 if( not defined $aug_type ) {
61 print STDERR
"Augmenter $name has no Type-field\n";
65 my $aug = eval "use NonameTV::Augmenter::$aug_type;
66 NonameTV::Augmenter::${aug_type}->new( \$aug_data, \$ds );"
71 =item CreateImporter( $name, $ds )
73 Create an importer from the configuration in $conf->{Importer}->{$name}
74 and associate it with the NonameTV::DataStore in $ds.
76 Returns the newly created importer or dies if creation fails.
81 my( $name, $ds ) = @_;
83 my $conf = ReadConfig
();
85 if( not exists( $conf->{Importers
}->{$name} ) ) {
86 print STDERR
"No such importer $name\n";
90 my $imp_data = $conf->{Importers
}->{$name};
91 $imp_data->{ConfigName
} = $name;
93 my $imp_type = $imp_data->{Type
};
95 if( not defined $imp_type ) {
96 print STDERR
"Importer $name has no Type-field\n";
100 my $imp = eval "use NonameTV::Importer::$imp_type;
101 NonameTV::Importer::${imp_type}->new( \$imp_data, \$ds );"
106 =item CreateExporter( $name, $ds )
108 Create an exporter from the configuration in $conf->{Exporter}->{$name}
109 and associate it with the NonameTV::DataStore in $ds.
111 Returns the newly created exporter or dies if creation fails.
116 my( $name, $ds ) = @_;
118 my $conf = ReadConfig
();
120 if( not exists( $conf->{Exporters
}->{$name} ) ) {
121 print STDERR
"No such exporter $name\n";
125 my $exp_data = $conf->{Exporters
}->{$name};
126 my $exp_type = $exp_data->{Type
};
128 my $exp = eval "use NonameTV::Exporter::$exp_type;
129 NonameTV::Exporter::${exp_type}->new( \$exp_data, \$ds );"
134 =item CreateFileStore( $importername )
136 Create a NonameTV::FileStore object that matches the configuration
139 Returns the newly created filestore or dies if creation fails.
143 sub CreateFileStore
{
144 my( $importername ) = @_;
146 require NonameTV
::FileStore
;
148 my $conf = ReadConfig
();
150 if( not exists( $conf->{Importers
}->{$importername} ) ) {
151 print STDERR
"No such importer $importername\n";
157 if( exists( $conf->{Importers
}->{$importername}->{FileStore
} ) ) {
158 $path = $conf->{Importers
}->{$importername}->{FileStore
};
160 elsif( exists( $conf->{FileStore
} ) ) {
161 $path = $conf->{FileStore
};
164 print STDERR
"No FileStore found in configuration for " .
165 "importer $importername.";
169 return NonameTV
::FileStore
->new( { Path
=> $path } );
172 =item CreateDataStore
174 Create a NonameTV::DataStore from the configuration.
176 Returns the newly created datastore or dies if creation fails.
177 If CreateDataStore is called more than once, the same DataStore object
178 will be returned avery time.
184 sub CreateDataStore
{
185 return $ds if defined $ds;
187 my $conf = ReadConfig
();
189 require NonameTV
::DataStore
;
190 $ds = NonameTV
::DataStore
->new( $conf->{DataStore
} );
195 =item CreateDataStoreDummy
197 Create a dummy datastore (see NonameTV::DataStore::Dummy) from the
200 Returns the newly created datastore or dies if creation fails.
204 sub CreateDataStoreDummy
{
205 my $conf = ReadConfig
();
207 require NonameTV
::DataStore
::Dummy
;
208 return NonameTV
::DataStore
::Dummy
->new( $conf->{DataStore
} );
213 Initialize the HTTP::Cache::Transparent module from the configuration.
218 require HTTP
::Cache
::Transparent
;
219 my $conf = ReadConfig
();
220 HTTP
::Cache
::Transparent
::init
( $conf->{Cache
} );