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';
18 has dir => (is => 'ro', isa => Dir, required => 1, coerce => 1);
20 method _target_files () {
21 grep $_->name =~ /\.csv$/, io($self->dir)->all_files;
24 method _expand_post (HashRef $post_spec) {
25 Post->new($post_spec);
28 method _expand_posts_from_file(IO::All::File $file) {
30 map $self->_expand_post($_),
31 @{$self->_expand_postspecs_from_file($file)},
35 method _csv_column_order () {
37 return map +($_ => $x++), qw(author title url at);
40 method _expand_postspecs_from_file(IO::All::File $file) {
41 my $csv = Text::CSV_XS->new;
44 my %col_order = $self->_csv_column_order;
45 while (my $post_raw = $csv->getline($io)) {
47 @post_spec{qw{url at}} = @{$post_raw}[@col_order{qw{url at}}];
48 push(@post_specs, \%post_spec);
53 method _expand_monger (IO::All::File $file) {
54 my ($name, $nick) = name_and_nick_from_filename($file->name);
56 (defined $name ? (name => $name) : ()),
57 (defined $nick ? (nick => $nick) : ()),
58 posts => $self->_expand_posts_from_file($file),
63 map $self->_expand_monger($_), $self->_target_files;