package TVGuide;
use strict;
use warnings;
use overload 
   '+' => 'add',
   '-' => 'subtract',
;

sub new {
   my $class = shift;
   my ($ch, $sched) = @_;

   my $self = { channel => $ch, schedule => $sched };

   bless $self, $class;
   return $self;
}

sub get_channel {
   my $self = shift;
   return $self->{channel};
}

sub get_show {
   my $self = shift;
   my $ch = shift;
   return $self->{schedule}{$ch};
}

sub now_showing {
   my $self = shift;
   return $self->get_show($self->get_channel());
}

sub change_channel {
   my $self = shift;
   my $ch = shift;
   $self->{channel} = $ch;
}

sub add_show {
   my $self = shift;
   my ($ch, $show) = @_;
   $self->{schedule}{$ch} = $show;
}

sub add {
   my $self = shift;
   my $num = shift;
   my $class = ref($self);
   my %schedule = %{$self->{schedule}};

   return $class->new($self->{channel} + $num, \%schedule);
}

sub subtract {
   my $self = shift;
   my $num = shift;
   my $class = ref($self);
   my %schedule = %{$self->{schedule}};

   return $class->new($self->{channel} - $num, \%schedule);
}

   

1;
