Skip to content

Commit

Permalink
Move event storage out of TB2::History and into a new TB2::History::E…
Browse files Browse the repository at this point in the history
…ventStorage object.

Then we can add an EventStorage that throws out events.

This was the last use of TB2::Stack and TB2::StackBuilder, so they're removed.

For #198
  • Loading branch information
schwern committed May 21, 2012
1 parent 581ee89 commit 9626992
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 347 deletions.
55 changes: 42 additions & 13 deletions lib/TB2/History.pm
Expand Up @@ -3,7 +3,6 @@ package TB2::History;
use Carp;
use TB2::Mouse;
use TB2::Types;
use TB2::StackBuilder;
use TB2::threads::shared;

with 'TB2::EventHandler',
Expand Down Expand Up @@ -86,20 +85,56 @@ Unless otherwise stated, these are all accessor methods of the form:
=head3 events
A TB2::Stack of events, that include Result objects.
my $events = $history->events;
An array ref of all events seen.
=cut

has event_storage =>
is => 'ro',
isa => 'TB2::History::EventStorage',
default => sub {
$_[0]->load("TB2::History::EventStorage");
return TB2::History::EventStorage->new;
};

sub events {
my $self = shift;
return $self->event_storage->events;
}

sub results {
my $self = shift;
return $self->event_storage->results;
}


=head3 event_count
Get the count of events that are on the stack.
my $count = $history->event_count;
Get the count of events that have been seen.
=cut

buildstack events => 'Any';
sub event_count {
my $self = shift;
my $events = $self->events;
return scalar @$events;
}

sub result_count {
my $self = shift;
my $results = $self->results;
return scalar @$results;
}

sub handle_event {
my $self = shift;
my $event = shift;

$self->events_push($event);
$self->event_storage->events_push($event);

return;
}
Expand Down Expand Up @@ -182,35 +217,29 @@ sub handle_set_plan {
return;
}

sub event_count { shift->events_count }
sub has_events { shift->events_count > 0 }
sub has_events { shift->event_count > 0 }

=head2 Results
=head3 results
A TB2::Stack of Result objects.
# The result of test #4.
my $result = $history->results->[3];
=cut

buildstack results => 'TB2::Result::Base';
sub handle_result {
my $self = shift;
my $result = shift;

$self->counter( $self->counter + 1 );

$self->results_push($result);
$self->events_push($result);
$self->event_storage->events_push($result);

$self->_update_statistics($result);

return;
}
sub result_count { shift->results_count }


=head2 result_count
Expand Down
89 changes: 89 additions & 0 deletions lib/TB2/History/EventStorage.pm
@@ -0,0 +1,89 @@
package TB2::History::EventStorage;

use TB2::Mouse;

=head1 NAME
TB2::History::EventStorage - Store all events
=head1 SYNOPSIS
my $storage = TB2::History::EventStorage->new;
$storage->event_push($event);
my $events = $storage->events;
my $results = $storage->results;
=head1 DESCRIPTION
This object stores L<TB2::Event>s.
=head2 Constructors
=head3 new
my $storage = TB2::History::EventStorage->new;
Create a new storage object.
=head2 Methods
=head3 events
my $events = $storage->events;
Returns all L<TB2::Event>s pushed in so far.
Do I<NOT> alter this array directly. Use L<events_push>.
=head3 results
my $results = $storage->results;
Returns just the L<TB2::Result>s pushed in so far.
Do I<NOT> alter this array directly. Use L<events_push>.
=cut

has events =>
is => 'ro',
isa => 'ArrayRef[TB2::Event]',
default => sub { [] }
;

has results =>
is => 'ro',
isa => 'ArrayRef[TB2::Result]',
default => sub { [] }
;


=head3 events_push
$storage->events_push(@events);
Add any number of @events to C<< $storage->events >>.
=cut

sub events_push {
my $self = shift;

push @{$self->events}, @_;
push @{$self->results}, grep $_->isa("TB2::Result::Base"), @_;

return;
}


=head1 SEE ALSO
L<TB2::History::NoEventStorage> is like EventStorage but it silently
throws away all events. Saves space.
=cut


1;
156 changes: 0 additions & 156 deletions lib/TB2/Stack.pm

This file was deleted.

0 comments on commit 9626992

Please sign in to comment.