add debug code
[engit/Iron-Munger.git] / lib / IronMunger / Monger.pm
1 use MooseX::Declare;
2
3 class IronMunger::Monger {
4
5   use MooseX::Types::Moose qw(ArrayRef Str);
6   use IronMunger::Calculate qw(:all);
7   use aliased 'IronMunger::Post';
8   use signatures;
9
10   has name => (is => 'ro', isa => Str, required => 0, predicate => 'has_name');
11   has nick => (is => 'ro', isa => Str, required => 0, predicate => 'has_nick');
12
13   method full_name () {
14     join(' aka ',$self->name||'nameless',$self->nick||'anoncow');
15   }
16
17   has posts => (
18     is => 'ro', isa => ArrayRef[Post], required => 1,
19     default => sub { [] },
20   );
21
22   has post_count => (
23     is => 'ro', lazy => 1,
24     default => sub ($self) { successful_sequential_posts(@{$self->posts}) },
25   );
26
27   has days_left => (
28     is => 'ro', lazy => 1,
29     default => sub ($self) { days_remaining_to_post(@{$self->posts}) },
30   );
31
32   has level => (
33     is => 'ro', lazy => 1,
34     default => sub ($self) { level_for_post_count($self->post_count) }
35   );
36
37   method debug_dump () {
38     join("\n",
39       (map join(': ', $_, $self->$_),
40         qw(full_name post_count days_left level)),
41       'Posts:',
42       join('',
43         map { my $x = $_->debug_dump; $x =~ s/^/  /m; $x; } @{$self->posts}
44       ),
45       ''
46     );
47   }
48 }
49
50 1;