start of stats saver code
Matt S Trout [Sat, 16 May 2009 20:17:20 +0000 (21:17 +0100)]
lib/IronMunger/StatsSaver.pm [new file with mode: 0644]
t/stats_saver.t [new file with mode: 0644]

diff --git a/lib/IronMunger/StatsSaver.pm b/lib/IronMunger/StatsSaver.pm
new file mode 100644 (file)
index 0000000..18c2e36
--- /dev/null
@@ -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 (file)
index 0000000..0eba022
--- /dev/null
@@ -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',
+);