From: Matt S Trout Date: Sat, 16 May 2009 20:17:20 +0000 (+0100) Subject: start of stats saver code X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=13a79a435b6db5b324dcdb1fb83a3a5d4429c813;p=engit%2FIron-Munger.git start of stats saver code --- diff --git a/lib/IronMunger/StatsSaver.pm b/lib/IronMunger/StatsSaver.pm new file mode 100644 index 0000000..18c2e36 --- /dev/null +++ b/lib/IronMunger/StatsSaver.pm @@ -0,0 +1,28 @@ +use MooseX::Declare; + +class IronMunger::StatsSaver { + + use MooseX::Types::Path::Class qw(Dir); + + has dir => (is => 'ro', isa => Dir, required => 1, coerce => 1); + + method _image_symlink_target (Str $type, Str $level) { + $self->dir->subdir('badges')->subdir($type)->file("${level}.png"); + } + + method _image_symlink_from (Str $user, Str $type) { + $self->dir->subdir('mybadge')->subdir($type)->file("${user}.png"); + } + + method _write_image_symlink (Str $user, Str $type, Str $level) { + my ($from, $target) = ( + $self->_image_symlink_from($user, $type), + $self->_image_symlink_target($type, $level), + ); + symlink($target, $from) + or confess "Couldn't symlink ${from} to ${target}: $!"; + return; + } +} + +1; diff --git a/t/stats_saver.t b/t/stats_saver.t new file mode 100644 index 0000000..0eba022 --- /dev/null +++ b/t/stats_saver.t @@ -0,0 +1,20 @@ +use strict; +use warnings; +use Test::More qw(no_plan); + +BEGIN { use_ok aliased => 'IronMunger::StatsSaver'; } + +ok( + (my $saver = StatsSaver->new(dir => 'X')), + 'Constructed object ok' +); + +is( + $saver->_image_symlink_target('male','iron'), 'X/badges/male/iron.png', + 'Symlink target ok', +); + +is( + $saver->_image_symlink_from('mst', 'female',), 'X/mybadge/female/mst.png', + 'Symlink from ok', +);