From: Matt S Trout Date: Sat, 16 May 2009 15:51:00 +0000 (+0100) Subject: add name and nick attributes to Monger object, add missing use line to PlaggerLoader X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f00c97c5fffc622f702d16f51e39985c9afecdc3;p=engit%2FIron-Munger.git add name and nick attributes to Monger object, add missing use line to PlaggerLoader --- diff --git a/lib/IronMunger/Monger.pm b/lib/IronMunger/Monger.pm index ec0683d..69190e2 100644 --- a/lib/IronMunger/Monger.pm +++ b/lib/IronMunger/Monger.pm @@ -2,11 +2,14 @@ use MooseX::Declare; class IronMunger::Monger { - use MooseX::Types::Moose qw(ArrayRef); + use MooseX::Types::Moose qw(ArrayRef Str); use IronMunger::Calculate qw(:all); use aliased 'IronMunger::Post'; use signatures; + has name => (is => 'ro', isa => Str, required => 0, predicate => 'has_name'); + has nick => (is => 'ro', isa => Str, required => 0, predicate => 'has_nick'); + has posts => ( is => 'ro', isa => ArrayRef[Post], required => 1, default => sub { [] }, diff --git a/lib/IronMunger/PlaggerLoader.pm b/lib/IronMunger/PlaggerLoader.pm index db50215..e3ef197 100644 --- a/lib/IronMunger/PlaggerLoader.pm +++ b/lib/IronMunger/PlaggerLoader.pm @@ -11,6 +11,7 @@ class IronMunger::PlaggerLoader { use IronMunger::CSVUtils qw(:all); use aliased 'IronMunger::Post'; + use aliased 'IronMunger::Monger'; use IO::All; use Text::CSV_XS; @@ -51,7 +52,7 @@ class IronMunger::PlaggerLoader { } method _expand_monger (IO::All::File $file) { - my ($name, $nick) = name_and_nick_from_filename($file->name); + my ($name, $nick) = filename_to_name_and_nick(($file->splitpath)[-1]); Monger->new( (defined $name ? (name => $name) : ()), (defined $nick ? (nick => $nick) : ()), diff --git a/t/plagger_loader.t b/t/plagger_loader.t index 43405f5..4ea59ef 100644 --- a/t/plagger_loader.t +++ b/t/plagger_loader.t @@ -56,3 +56,16 @@ foreach my $i (0, 1) { } } +my $jdv = $loader->_expand_monger($jdv_file); + +is($jdv->name, 'Justin DeVuyst', 'Name correct'); +ok(!$jdv->has_nick, 'No nickname'); +cmp_ok(@{$jdv->posts}, '==', 2, '2 posts loaded'); + +my @mongers = sort { $a->name cmp $b->name } $loader->mongers; + +cmp_ok(scalar(@mongers), '==', 2, '2 mongers loaded'); + +foreach my $i (0, 1) { + is($mongers[$i]->name, $names[$i], $names[$i].' loaded'); +}