add strictures commit (out of order)
[catagits/HTML-Zoom.git] / lib / HTML / Zoom / ZConfig.pm
1 package HTML::Zoom::ZConfig;
2
3 use strictures 1;
4
5 my %DEFAULTS = (
6   parser => 'HTML::Zoom::Parser::BuiltIn',
7   producer => 'HTML::Zoom::Producer::BuiltIn',
8   filter_builder => 'HTML::Zoom::FilterBuilder',
9   selector_parser => 'HTML::Zoom::SelectorParser',
10   stream_utils => 'HTML::Zoom::StreamUtils',
11 );
12
13 my $ALL_DEFAULT;
14
15 sub new {
16   my ($class, $args) = @_;
17   return $ALL_DEFAULT if $ALL_DEFAULT && !keys %{$args||{}};
18   my $new = {};
19   foreach my $arg_name (keys %DEFAULTS) {
20     $new->{$arg_name} = $args->{$arg_name} || $DEFAULTS{$arg_name};
21     if (ref($new->{$arg_name})) {
22       $new->{$arg_name} = $new->{$arg_name}->with_zconfig($new);
23     } else {
24       require(do { (my $m = $new->{$arg_name}) =~ s/::/\//g; "${m}.pm" });
25       $new->{$arg_name} = $new->{$arg_name}->new({ zconfig => $new });
26     }
27   }
28   $ALL_DEFAULT = $new if !keys %{$args||{}};
29   bless($new, $class);
30 }
31
32 sub parser { shift->{parser} }
33 sub producer { shift->{producer} }
34 sub filter_builder { shift->{filter_builder} }
35 sub selector_parser { shift->{selector_parser} }
36 sub stream_utils { shift->{stream_utils} }
37
38 1;