From: Matt S Trout Date: Fri, 22 May 2009 08:24:03 +0000 (+0100) Subject: start to test symlink code, break it utterly X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=79810d7d56e481a0f789eb77eb4c53f4b23fb6c5;p=engit%2FIron-Munger.git start to test symlink code, break it utterly --- diff --git a/lib/IronMunger/Monger.pm b/lib/IronMunger/Monger.pm index 69190e2..5b844b7 100644 --- a/lib/IronMunger/Monger.pm +++ b/lib/IronMunger/Monger.pm @@ -24,6 +24,11 @@ class IronMunger::Monger { is => 'ro', lazy => 1, default => sub ($self) { days_remaining_to_post(@{$self->posts}) }, ); + + has level => ( + is => 'ro', lazy => 1, + default => sub ($self) { level_for_post_count($self->post_count) } + ); } 1; diff --git a/lib/IronMunger/StatsSaver.pm b/lib/IronMunger/StatsSaver.pm index 18c2e36..3fd1e5b 100644 --- a/lib/IronMunger/StatsSaver.pm +++ b/lib/IronMunger/StatsSaver.pm @@ -3,9 +3,16 @@ use MooseX::Declare; class IronMunger::StatsSaver { use MooseX::Types::Path::Class qw(Dir); + use aliased 'IronMunger::Monger'; + use IO::All; + use File::Path qw(mkpath); + use Text::CSV_XS; + use namespace::autoclean; has dir => (is => 'ro', isa => Dir, required => 1, coerce => 1); + my @types = qw(male female); + method _image_symlink_target (Str $type, Str $level) { $self->dir->subdir('badges')->subdir($type)->file("${level}.png"); } @@ -19,10 +26,29 @@ class IronMunger::StatsSaver { $self->_image_symlink_from($user, $type), $self->_image_symlink_target($type, $level), ); + my $dir = File::Spec->catpath((File::Spec->splitpath($target))[0,1]); + mkpath($dir); symlink($target, $from) or confess "Couldn't symlink ${from} to ${target}: $!"; return; } + + method _write_symlinks_for (IronMunger::Monger $monger) { + foreach my $type (@types) { + foreach my $name (map $monger->$_, qw(name nick)) { + $self->_write_image_symlink($name, $type, $monger->level); + } + } + } + + method _write_summary_csv (ArrayRef[IronMunger::Monger] $mongers) { + } + + method mongers (ArrayRef[IronMunger::Monger] $mongers) { + $self->_write_summary_csv($mongers); + $self->_write_symlinks_for($_) for @$mongers; + } + } 1; diff --git a/t/stats_saver.t b/t/stats_saver.t index 0eba022..4ffddd1 100644 --- a/t/stats_saver.t +++ b/t/stats_saver.t @@ -1,8 +1,11 @@ use strict; use warnings; use Test::More qw(no_plan); +use IO::All; +use File::Temp qw(tempdir); BEGIN { use_ok aliased => 'IronMunger::StatsSaver'; } +BEGIN { use_ok aliased => 'IronMunger::Monger'; } ok( (my $saver = StatsSaver->new(dir => 'X')), @@ -15,6 +18,23 @@ is( ); is( - $saver->_image_symlink_from('mst', 'female',), 'X/mybadge/female/mst.png', + $saver->_image_symlink_from('mst', 'female'), 'X/mybadge/female/mst.png', 'Symlink from ok', ); + +my $monger = Monger->new( + nick => 'mst', + posts => [] +); + +is($monger->level, 'paper', 'mst sucks'); + +my $dir = tempdir(CLEANUP => 1); + +$saver = StatsSaver->new(dir => $dir); + +$saver->_write_symlinks_for($monger); + +my @links = sort map $_->readlink, grep -l, io($dir)->all_files; + +warn join("\n", @links);