PageRenderTime 232ms CodeModel.GetById 110ms app.highlight 7ms RepoModel.GetById 114ms app.codeStats 0ms

/lib/Teto/Control.pm

http://github.com/motemen/Teto
Perl | 42 lines | 32 code | 10 blank | 0 comment | 1 complexity | 159f011011667f20c958fe1b0cdc1471 MD5 | raw file
 1package Teto::Control;
 2use Mouse;
 3use Teto::Queue;
 4use Teto::Playlist;
 5use Teto::Worker::FeedTracksToQueue;
 6
 7with 'Teto::Role::Log';
 8
 9has queue => (
10    is  => 'rw',
11    isa => 'Teto::Queue',
12    default => sub { Teto::Queue->new },
13);
14
15has playlist => (
16    is  => 'rw',
17    isa => 'Teto::Playlist',
18);
19
20__PACKAGE__->meta->make_immutable;
21
22no Mouse;
23
24sub BUILD {
25    my $self = shift;
26
27    my $playlist = (values %{ Teto::Playlist->all })[-1];
28    $self->set_playlist($playlist);
29}
30
31sub set_playlist {
32    my ($self, $playlist) = @_;
33    $self->playlist($playlist);
34
35    $self->{worker}->dismiss if $self->{worker};
36    $self->{worker} = Teto::Worker::FeedTracksToQueue->spawn(
37        playlist => $self->playlist,
38        queue    => $self->queue,
39    );
40}
41
421;