Git::PurePerl::Walker - Walk over a sequence of commits in a Git::PurePerl repo
version 0.004002
use Git::PurePerl::Walker;
use Git::PurePerl::Walker::Method::FirstParent;
my $repo = Git::PurePerl->new( ... );
my $walker = Git::PurePerl::Walker->new(
repo => $repo,
method => Git::PurePerl::Walker::Method::FirstParent->new(
start => $repo->ref_sha1('refs/heads/master'),
),
on_commit => sub {
my ( $commit ) = @_;
print $commit->sha1;
},
);
$walker->step_all;
Mandatory: An instance of Git::PurePerl
representing
the repository to work with.
Mandatory: either a Str
describing a Class Name Suffix, or an Object
that does
Git::PurePerl::**Walker::Role::Method**
.
If its a Str
, the Str
will be expanded as follows:
->new(
...
method => 'Foo',
...
);
$className = 'Git::PurePerl::Walker::Method::Foo'
And the resulting class will be loaded, and instantiated for you. ( Assuming of course, you don't need to pass any fancy args ).
If you need fancy args, or a class outside the
Git::PurePerl::**Walker::Method::**
namespace, constructing the object will
have to be your responsibility.
->new(
...
method => Foo::Class->new(),
...
)
Mandatory: either a Str
that can be expanded in a way similar to that by
_method_
, a CodeRef
, or an object that does
Git::PurePerl::**Walker::Role::OnCommit**
.
If passed a Str
it will be expanded like so:
->new(
...
on_commit => $str,
...
);
$class = 'Git::PurePerl::Walker::OnCommit::' . $str;
And the resulting class loaded and instantiated.
If passed a CodeRef
,
Git::PurePerl::**Walker::OnCommit::CallBack**
will be loaded and your CodeRef
will be passed as an argument.
->new(
...
on_commit => sub {
my ( $commit ) = @_;
},
...
);
If you need anything fancier, or requiring an unusual namespace, you'll want to construct the object yourself.
->new(
...
on_commit => Foo::Package->new()
...
);
$walker->reset();
Reset the walk routine back to the state it was before you walked.
Increments one step forward in the git history, and dispatches the object to the
OnCommit
handlers.
If there are more possible steps to take, it will return a true value.
while ( $walker->step ) {
/* Code to execute if walker has more items */
}
This code is almost identical to:
while(1) {
$walker->on_commit->handle( $walker->method->current );
last if not $walker->method->has_next;
$walker->method->next;
/* Code to execute if walker has more items */
}
my $steps = $walker->step_all;
Mostly a convenience method to iterate until it can iterate no more, but without you needing to wrap it in a while() block.
Returns the number of steps executed.
# Getter
my $repo = $walker->repo();
# Getter
my $method_object = $walker->method();
# Getter
my $on_commit_object = $walker->on_commit();
# Getter
my $methodish = $walker->_method();
# Getter
my $on_commitish => $walker->_on_commit();
Kent Fredric kentnl@cpan.org
This software is copyright (c) 2017 by Kent Fredric kentnl@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.