clean up and get the integration code to make a first run
[engit/Iron-Munger.git] / lib / IronMunger / StatsSaver.pm
CommitLineData
13a79a43 1use MooseX::Declare;
2
3class IronMunger::StatsSaver {
4
5 use MooseX::Types::Path::Class qw(Dir);
79810d7d 6 use aliased 'IronMunger::Monger';
7 use IO::All;
8 use File::Path qw(mkpath);
9 use Text::CSV_XS;
13a79a43 10
11 has dir => (is => 'ro', isa => Dir, required => 1, coerce => 1);
12
79810d7d 13 my @types = qw(male female);
14
13a79a43 15 method _image_symlink_target (Str $type, Str $level) {
16 $self->dir->subdir('badges')->subdir($type)->file("${level}.png");
17 }
18
19 method _image_symlink_from (Str $user, Str $type) {
20 $self->dir->subdir('mybadge')->subdir($type)->file("${user}.png");
21 }
22
23 method _write_image_symlink (Str $user, Str $type, Str $level) {
24 my ($from, $target) = (
25 $self->_image_symlink_from($user, $type),
26 $self->_image_symlink_target($type, $level),
27 );
b5b2a791 28 my $dir = File::Spec->catpath((File::Spec->splitpath($from))[0,1]);
79810d7d 29 mkpath($dir);
13a79a43 30 symlink($target, $from)
31 or confess "Couldn't symlink ${from} to ${target}: $!";
32 return;
33 }
79810d7d 34
35 method _write_symlinks_for (IronMunger::Monger $monger) {
36 foreach my $type (@types) {
b5b2a791 37 foreach my $name (
38 map $monger->$_,
39 grep $monger->${\"has_$_"},
40 qw(name nick)
41 ) {
79810d7d 42 $self->_write_image_symlink($name, $type, $monger->level);
43 }
44 }
45 }
46
47 method _write_summary_csv (ArrayRef[IronMunger::Monger] $mongers) {
48 }
49
50 method mongers (ArrayRef[IronMunger::Monger] $mongers) {
51 $self->_write_summary_csv($mongers);
52 $self->_write_symlinks_for($_) for @$mongers;
53 }
54
13a79a43 55}
56
571;