/lib/Teto/Control.pm

http://github.com/motemen/Teto · Perl · 42 lines · 32 code · 10 blank · 0 comment · 1 complexity · 159f011011667f20c958fe1b0cdc1471 MD5 · raw file

  1. package Teto::Control;
  2. use Mouse;
  3. use Teto::Queue;
  4. use Teto::Playlist;
  5. use Teto::Worker::FeedTracksToQueue;
  6. with 'Teto::Role::Log';
  7. has queue => (
  8. is => 'rw',
  9. isa => 'Teto::Queue',
  10. default => sub { Teto::Queue->new },
  11. );
  12. has playlist => (
  13. is => 'rw',
  14. isa => 'Teto::Playlist',
  15. );
  16. __PACKAGE__->meta->make_immutable;
  17. no Mouse;
  18. sub BUILD {
  19. my $self = shift;
  20. my $playlist = (values %{ Teto::Playlist->all })[-1];
  21. $self->set_playlist($playlist);
  22. }
  23. sub set_playlist {
  24. my ($self, $playlist) = @_;
  25. $self->playlist($playlist);
  26. $self->{worker}->dismiss if $self->{worker};
  27. $self->{worker} = Teto::Worker::FeedTracksToQueue->spawn(
  28. playlist => $self->playlist,
  29. queue => $self->queue,
  30. );
  31. }
  32. 1;