1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
package SVK;
use strict;
use SVK::Version; our $VERSION = $SVK::VERSION;
# Load classes on demand.
use Class::Autouse qw(SVK::Command);
use SVN::Core;
BEGIN {
# autouse hates Devel::DProf. If we're running with DProf,
# we need to emasculate autouse by blowing a new import sub into its
# package at runtime.
if($main::INC{'Devel/DProf.pm'}) {
no strict 'refs';
$main::INC{'autouse.pm'} = __FILE__;
*{'autouse::import'} = sub {
require UNIVERSAL::require;
shift; # get rid of $CLASS
my $class = shift;
$class->require or die "$class: $!";
my @arg = @_;
$class->export_to_level(1, undef, map {s/\(.*\)//g;$_} @arg);
}
}
}
sub import {
return unless ref ($_[0]);
our $AUTOLOAD = 'import';
goto &AUTOLOAD;
}
sub new {
my $class = shift;
my $self = bless {}, $class;
%$self = @_;
return $self;
}
sub AUTOLOAD {
my $cmd = our $AUTOLOAD;
$cmd =~ s/^SVK:://;
return if $cmd =~ /^[A-Z]+$/;
no strict 'refs';
no warnings 'redefine';
*$cmd = sub {
my $self = shift;
my ($buf, $output, $ret) = ('');
open $output, '>', \$buf if $self->{output};
eval { $ret = SVK::Command->invoke ($self->{xd}, $cmd, $output, @_) };
if ($output) {
close $output;
${$self->{output}} = $buf;
}
return $ret;
};
goto &$cmd;
}
1;
__DATA__
=head1 NAME
SVK - A Distributed Version Control System
=head1 SYNOPSIS
use SVK;
use SVK::XD;
$xd = SVK::XD->new (depotmap => { '' => '/path/to/repos'});
$svk = SVK->new (xd => $xd, output => \$output);
# serialize the $xd object for future use.
$svk->ls ('//'); # check $output for its output
...
=head1 DESCRIPTION
C<SVK> is the class that loads L<SVK::Command> and invokes them. You can
use it in your program to do what you do with the L<svk> command line
interface.
=head1 CONSTRUCTOR
Options to C<new>:
=over
=item xd
L<SVK::XD> object that handles depot and checkout copy mapping.
=item output
A scalar reference. After command invocation the output will be stored
in the scalar. By default the output is not held in any scalar and
will be printed to STDOUT.
=back
=head1 METHODS
All methods are autoloaded and deferred to
C<SVK::Command-E<gt>invoke>.
=head1 SEE ALSO
L<svk>, L<SVK::XD>, L<SVK::Command>.
=head1 AUTHORS
Chia-liang Kao E<lt>clkao@clkao.orgE<gt>
=head1 COPYRIGHT
Copyright 2003-2005 by Chia-liang Kao E<lt>clkao@clkao.orgE<gt>.
This program is free software; you can redistribute it and/or modify it
under the same terms as Perl itself.
See L<http://www.perl.com/perl/misc/Artistic.html>
=cut
|