Separate out App::IdiotBox::* DB objects and put create/update
[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
9sub slug { shift->{slug} }
10sub name { shift->{name} }
11sub video_count {
12 exists $_[0]->{video_count}
13 ? $_[0]->{video_count}
14 : $_[0]->{videos}->count
15}
16sub videos { shift->{videos} }
17
18sub create {
19 my ($class, %args) = @_;
20
21 unless ($args{name} && $args{slug}) {
22 return (undef, "Please enter a name and a bucket");
23 }
24 if ($args{name} =~ /^\s+$/ || $args{slug} =~ /^\s+$/) {
25 return (undef, "Names/buckets must not be all whitespace");
26 }
27
28 $args{slug} =~ s/\s+/-/g;
29
30 return bless {
31 name => $args{name},
32 slug => $args{slug},
33 }, $class;
34}
35
36sub update {
37 my ($self, %args) = @_;
38
39 unless ($args{name}) {
40 return (undef, "Please enter a new name");
41 }
42
43 if ($args{name} =~ /^\s+$/) {
44 return (undef, "Names must not be all whitespace");
45 }
46
47 $self->{name} = $args{name};
48
49 $self->clone;
50}
51
521;