New admin UI functionality.
[catagits/App-IdiotBox.git] / lib / App / IdiotBox / Bucket.pm
CommitLineData
f29e9b6f 1package App::IdiotBox::Bucket;
2
3use Moo;
4
5sub fields { return qw(slug name) }
6
7with 'App::IdiotBox::Clonable';
8
f29e9b6f 9sub name { shift->{name} }
2da7f57f 10sub slug { shift->{slug} }
11sub videos { shift->{videos} }
12#has 'name' => (is => 'rw');
13#has 'slug' => (is => 'rw');
14#has 'videos' => (is => 'rw');
15has '_video_count' => (is => 'rw');
16
f29e9b6f 17sub video_count {
2da7f57f 18 my $self = shift;
19
20 return $self->_video_count if defined $self->_video_count;
21
22 return $self->{video_count} if defined $self->{video_count};
23
24 return $self->videos->count;
f29e9b6f 25}
f29e9b6f 26
27sub create {
28 my ($class, %args) = @_;
29
30 unless ($args{name} && $args{slug}) {
31 return (undef, "Please enter a name and a bucket");
32 }
33 if ($args{name} =~ /^\s+$/ || $args{slug} =~ /^\s+$/) {
34 return (undef, "Names/buckets must not be all whitespace");
35 }
36
37 $args{slug} =~ s/\s+/-/g;
38
2da7f57f 39 return App::IdiotBox::Bucket->new(
f29e9b6f 40 name => $args{name},
41 slug => $args{slug},
2da7f57f 42 );
f29e9b6f 43}
44
45sub update {
46 my ($self, %args) = @_;
47
48 unless ($args{name}) {
49 return (undef, "Please enter a new name");
50 }
51
52 if ($args{name} =~ /^\s+$/) {
53 return (undef, "Names must not be all whitespace");
54 }
55
2da7f57f 56 my $new = $self->clone;
57
58 $new->{name} = $args{name};
f29e9b6f 59
2da7f57f 60 return $new;
f29e9b6f 61}
62
631;