App-SnerpVortex

 view release on metacpan or  search on metacpan

lib/SVN/Dump/Walker.pm  view on Meta::CPAN

package SVN::Dump::Walker;
BEGIN {
  $SVN::Dump::Walker::VERSION = '1.000';
}

# Base class for higher-level objects that process SVN::Dump streams.
# Does some fundamental handling of SVN::Dump events, then provides
# slightly higher level events to callbacks.

# TODO - Basically done.  Think twice if you think it requires
# modification.

use lib qw(../SVN-Dump/lib ./lib);

use Moose;
use SVN::Dump;

has svn_dump_filename => (
	is        => 'ro',
	isa       => 'Str',
	required  => 1,
);

has current_revision => (
	is      => 'rw',
	isa     => 'Int',
	reader  => 'get_current_revision',
	writer  => 'set_current_revision',
);

has svn_dump => (
	is      => 'ro',
	isa     => 'SVN::Dump',
	lazy    => 1,
	default => sub {
		my $self = shift;
		return SVN::Dump->new(
			{ file => $self->svn_dump_filename() },
		);
	},
);

has include_regexp => (
	is	=> 'ro',
	isa	=> 'Maybe[RegexpRef]',
);

# ($self, $revision)
sub on_revision_done { undef }

# ($self, $revision, $author, $date, $log_message)
sub on_revision { undef }

# ($self, $revision, $path, $kind, $data)
sub on_node_add { undef }

# ($self, $revision, $path, $kind, $data)
sub on_node_change { undef }

# ($self, $revision, $path, $kind, $data)
sub on_node_replace { undef }

# ($self, $revision, $path)
sub on_node_delete { undef }

# ($self, $revision, $path, $kind, $from_rev, $from_path, $data)
sub on_node_copy { undef }

lib/SVN/Dump/Walker.pm  view on Meta::CPAN

__END__

=head1 NAME

SVN::Dump::Walker - A callback interface for SVN::Dump.

=head1 SYNOPSIS

Subclass SVN::Dump::Walker to perform some task.  Moose is optional.
This is an abbreviated version of L<SVN::Dump::AuthorExtractor>:

	package SVN::Dump::AuthorExtractor;
	use Moose;
	extends qw(SVN::Dump::Walker);

	has authors => (
		is      => 'rw',
		isa     => 'HashRef[Str]',
		default => sub { {} }
	);

	sub on_revision {
		my ($self, $revision, $author, $date, $log_message) = @_;
		$author = "(no author)" unless defined $author and length $author;
		$self->authors()->{$author} = 1;
	}

	sub on_walk_done {
		my $self = shift;
		foreach my $author (sort keys %{$self->authors()}) {
			print "$author = <$author\@" . $self->svn_dump()->uuid() . ">\n";
		}
	}

	1;

And the subclass is used.  This is an abbreviated version of
L<snauthors>:

	my $replayer = SVN::Dump::AuthorExtractor->new(
		svn_dump_filename => "subversion.dump",
	);

	$replayer->walk();
	exit;

=head1 DESCRIPTION

SVN::Dump::Walker walks a Subversion dump with SVN::Dump, calling back
specific methods for each record.

=head2 Construction

SVN::Dump::Walker takes a few basic constructor parameters.

C<svn_dump_filename> should contain the name of a Subversion dump
file.  It's required.

C<include_regexp> may contain a regular expression defining the
directories and files to include in the walk.  Those that don't match
won't trigger callbacks.  Optional.

=head2 Public Methods

=head3 walk

Start the walker's SVN::Dump loop.  Callbacks will be produced until
an error occurs or the file is completely traversed.

=head2 Callback Methods

=head3 on_walk_begin

An initial callback when walk() has begun.

Called with only one parameter, $self.

=head3 on_walk_done

A final callback when SVN::Dump is done and walk() is about to return.

Called with only one parameter, $self.

=head3 on_revision

Called whenever a new Subversion revision begins.

Called with five parameters: $self, the revision number, its author,
the time the revision was committed ("svn:date" property), and the
corresponding log message ("svn:log" property).

=head3 on_revision_done

Called whenever a Subversion revision has been committed.

Called with two parameters: $self and the revision number.

=head3 on_node_add

Called whenever SVN::Dump encounters an "add" action that is not a
copy.  For adds that are copies, see on_node_copy().

Called with five parameters: $self, the revision number, the path of
the thing being added, the kind of thing being added ("file" or
"dir"), and optionally the contents of the thing being added.

=head3 on_node_change

Called whenever SVN::Dump encounters a "change" action that is not a
copy.  For changes that are copies, see on_node_copy().

Called with five parameters: $self, the revision number, the path of
the thing being changed, the kind of thing being changed ("file" or
"dir"), and optionally the contents of the thing being changed.

=head3 on_node_replace

Called whenever SVN::Dump encounters a "replace" action that is not a
copy.  For replacements that are copies, see on_node_copy().

Called with five parameters: $self, the revision number, the path of



( run in 1.793 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )