3 class IronMunger::PlaggerLoader {
5 use MooseX::Types::Path::Class qw(Dir);
6 use MooseX::Types::Moose qw(HashRef);
7 use Moose::Util::TypeConstraints qw(class_type);
9 BEGIN { class_type 'IO::All::File'; }
11 use IronMunger::CSVUtils qw(:all);
13 use aliased 'IronMunger::Post';
14 use aliased 'IronMunger::Monger';
19 has dir => (is => 'ro', isa => Dir, required => 1, coerce => 1);
21 method _target_files () {
22 grep $_->name =~ /\.csv$/, io($self->dir)->all_files;
25 method _expand_post (HashRef $post_spec) {
26 Post->new($post_spec);
29 method _expand_posts_from_file(IO::All::File $file) {
31 map $self->_expand_post($_),
32 @{$self->_expand_postspecs_from_file($file)},
36 method _csv_column_order () {
38 return map +($_ => $x++), qw(author title url at);
41 method _expand_postspecs_from_file(IO::All::File $file) {
42 my $csv = Text::CSV_XS->new;
45 my %col_order = $self->_csv_column_order;
46 while (my $post_raw = $csv->getline($io)) {
48 @post_spec{qw{url at}} = @{$post_raw}[@col_order{qw{url at}}];
49 next unless $post_spec{url} && $post_spec{at};
50 push(@post_specs, \%post_spec);
55 method _expand_monger (IO::All::File $file) {
56 my ($name, $nick) = filename_to_name_and_nick(($file->splitpath)[-1]);
58 (defined $name ? (name => $name) : ()),
59 (defined $nick ? (nick => $nick) : ()),
60 posts => $self->_expand_posts_from_file($file),
65 map $self->_expand_monger($_), $self->_target_files;