File Coverage

blib/lib/Pinto/RevisionWalker.pm
Criterion Covered Total %
statement 18 18 100.0
branch 3 4 75.0
condition n/a
subroutine 5 5 100.0
pod 0 1 0.0
total 26 28 92.8


line stmt bran cond sub pod time code
1             # ABSTRACT: Iterates through revision history
2              
3             package Pinto::RevisionWalker;
4              
5 1     1   7 use Moose;
  1         2  
  1         6  
6 1     1   6036 use MooseX::StrictConstructor;
  1         2  
  1         10  
7 1     1   3056 use MooseX::Types::Moose qw(ArrayRef);
  1         2  
  1         8  
8 1     1   4432 use MooseX::MarkAsMethods ( autoclean => 1 );
  1         2  
  1         6  
9              
10             #------------------------------------------------------------------------------
11              
12             our $VERSION = '0.13'; # VERSION
13              
14             #------------------------------------------------------------------------------
15             # TODO: Rethink this API. Do we need start? Can we just use queue? What
16             # about filtering, or walking forward? Sort chronological or topological?
17              
18             has start => (
19             is => 'ro',
20             isa => 'Pinto::Schema::Result::Revision',
21             required => 1,
22             );
23              
24             has queue => (
25             isa => ArrayRef,
26             traits => [qw(Array)],
27             handles => { enqueue => 'push', dequeue => 'shift' },
28             default => sub { [ $_[0]->start ] },
29             lazy => 1,
30             );
31              
32             #------------------------------------------------------------------------------
33              
34             sub next {
35 5     5 0 149 my ($self) = @_;
36              
37 5         180 my $next = $self->dequeue;
38              
39 5 50       26 return if not $next;
40 5 100       286 return if $next->is_root;
41              
42 3         17 $self->enqueue( $next->parents );
43              
44 3         15 return $next;
45             }
46              
47             #------------------------------------------------------------------------------
48              
49             __PACKAGE__->meta->make_immutable;
50              
51             #-------------------------------------------------------------------------------
52             1;
53              
54             __END__
55              
56             =pod
57              
58             =encoding UTF-8
59              
60             =for :stopwords Jeffrey Ryan Thalhammer
61              
62             =head1 NAME
63              
64             Pinto::RevisionWalker - Iterates through revision history
65              
66             =head1 VERSION
67              
68             version 0.13
69              
70             =head1 AUTHOR
71              
72             Jeffrey Ryan Thalhammer <jeff@stratopan.com>
73              
74             =head1 COPYRIGHT AND LICENSE
75              
76             This software is copyright (c) 2015 by Jeffrey Ryan Thalhammer.
77              
78             This is free software; you can redistribute it and/or modify it under
79             the same terms as the Perl 5 programming language system itself.
80              
81             =cut