use strict 'no unwrapped candy'; use warnings 'look out for cars'; use constant HOME_BY => '8:00'; use constant CAN_EAT_TONIGHT => 1; sub halloween { my $self = shift; my $costume = shift or die "Can't have Halloween without a costume!"; $self->put_on($costume) or die "Costume doesn't fit, choose another one"; my @houses = $self->neighorhood->houses; my $is_dark_out = 0; while ( ! $is_dark_out && @houses ) { my $house = shift @houses; next if $house->owned_by eq 'stranger' || ! $house->light_on; $self->approach($house) or do { warn "House is too scary"; next; } my $rc = $house->knock(); if ($rc =~ /^tr(ick|eat)$/) { $self->candy->add($rc) if $rc->wrapped; } else { push @{ $self->jerks_i_know }, $house; $self->tp($house) unless $self->mom->watching; } $is_dark_out = 1 if $self->watch->time() > HOME_BY && ! $self->beg_for_more_time; } $self->approach($self->home) or die "Mommy! I'm lost"; $self->take_off($costume); my $num_eaten = 0; # note - should re-factor into separate method to be portable to other holidays, # but I'm busy eating sweet, sweet chocolate. EAT_CANDY: while (1) { my $piece = shift @{ $self->candy }; $self->eat($piece); $num_eaten++; if ( $self->mom->watching && $num_eaten > CAN_EAT_TONIGHT ) { # note - bug. This method always returns 0. last if ! $self->beg_for_one_more_piece; } } if ($num_eaten > 5) { sleep $self->watch->delta($self->watch->time, "2am"); $self->wake_up; $self->throw_up; goto EAT_CANDY; } if ( @{ $self->candy } ) { goto EAT_CANDY; } return $self->wait_for("christmas candy"); }