1package FEAR::API::Extract;
2
3use strict;
4use utf8;
5
6use Data::Dumper;
7use File::Spec::Functions qw(catfile splitpath);
8
9my $extractor_path = __FILE__;
10$extractor_path =~ s/\.pm$//o;
11
12
13sub new {
14    my $class = shift;
15    my $method = shift;
16
17    my $extractor_file = catfile($extractor_path, $method) . '.pm';
18    $extractor_file =~ s/::/./go;
19    require $extractor_file;
20
21    my $extractor_package = 'FEAR::API::Extract::'.$method;
22
23    my $r = bless {
24		   method => $method,
25		   extor => $extractor_package->new(),
26		  } => $class;
27    return $r;
28}
29
30sub new_all {
31    return
32	map { $_ => __PACKAGE__->new($_) }
33        map {
34		$_ = (splitpath($_))[2];
35		s/\.pm$//o;
36		s/\./::/go;
37		$_
38        }
39	grep{ !m(/Base\.pm$)o }
40        glob catfile($extractor_path, '*.pm');
41}
42
43sub extract {
44    my $self = shift;
45    my %arg = @_;
46    my $template = $arg{template};
47    my $document = $arg{document};
48    my $r;
49
50    $r = $self->{extor}->extract(\$template, \$document);
51    return $r;
52}
53
541;
55