--- /dev/null
+use MooseX::Declare;
+
+class IronMunger {
+
+ our $VERSION = '0.001000';
+
+ use aliased 'IronMunger::Monger';
+ use aliased 'IronMunger::PlaggerLoader';
+ use aliased 'IronMunger::StatsSaver';
+
+ use MooseX::Types::Moose qw(HashRef ClassName Str);
+
+ has mongers => (
+ is => 'ro', isa => HashRef[Monger], required => 1
+ default => sub { {} },
+ );
+
+ method load_from_plagger (ClassName $class: Str $dir) {
+ my $loader = PlaggerLoader->new(dir => $dir);
+ my $munger = $class->new;
+ $munger->mongers->{$_->full_name}
+ = $_ for @{$loader->mongers};
+ }
+
+ method save_monger_stats (Str $dir) {
+ my $saver = StatsSaver->new(dir => $dir);
+ $saver->mongers([ sort $_->full_name, values %{$self->mongers} ]);
+ }
+}
+
+1;
--- /dev/null
+use MooseX::Declare;
+
+class IronMunger::PlaggerLoader {
+
+ use MooseX::Types::Path::Class qw(Dir);
+ use MooseX::Types::Moose qw(HashRef);
+ use Moose::Util::TypeConstraints qw(class_type);
+
+ BEGIN { class_type 'IO::All::File'; }
+
+ use IronMunger::CSVUtils qw(:all);
+
+ use aliased 'IronMunger::Post';
+
+ use IO::All;
+ use Text::CSV_XS;
+
+ has dir => (is => 'ro', isa => Dir, required => 1, coerce => 1);
+
+ method _target_files () {
+ grep $_->name =~ /\.csv$/, io($self->dir)->get_files;
+ }
+
+ method _expand_post (HashRef $post_spec) {
+ Post->new($post_spec);
+ }
+
+ method _expand_posts_from_file(IO::All::File $file) {
+ return [
+ map $self->_expand_post($_),
+ @{$self->_expand_postspecs_from_file($file)},
+ ];
+ }
+
+ method _expand_postspecs_from_file(IO::All::File $file) {
+ my $csv = Text::CSV_XS->new;
+ my $io = $file->open;
+ my @post_specs;
+ while (my $post_raw = $csv->getline($io)) {
+ my %post_spec;
+ @post_spec{qw{url at}} = @{$post_raw}[1,2];
+ push(@post_specs, %post_spec);
+ }
+ return \@post_specs;
+ }
+
+ method _expand_monger (IO::All::File $file) {
+ my ($name, $nick) = name_and_nick_from_filename($file->name);
+ Monger->new(
+ (defined $name ? (name => $name) : ()),
+ (defined $nick ? (nick => $nick) : ()),
+ posts => $self->_expand_posts_from_file($file),
+ );
+ }
+
+ method mongers () {
+ map $self->_expand_monger($_), $self->_target_files;
+ }
+}
+
+1;