Cvs-Simple

 view release on metacpan or  search on metacpan

lib/Cvs/Simple.pm  view on Meta::CPAN


  my($commit_callback);
  my($commit) = 0;
  {
    my($file) = 'file.txt';
    ($commit_callback) = sub {
      my($cmd,$arg) = @_;
      if($arg=~/Checking in $file;/) { ++$commit }
    };
  }
  my($cvs) = Cvs::Simple->new();
  $cvs->callback(commit => $commit_callback);
  $cvs->add('file.txt');
  $cvs->commit();
  croak "Failed to commit file.txt" unless($commit);
  $cvs->unset_callback('commit');


=head1 DESCRIPTION

C<Cvs::Simple> is an attempt to provide an easy-to-use wrapper that allows cvs
commands to be executed from within a Perl program, without the programmer having to
wade through the (many) cvs global and command-specific options.

The methods provided follow closely the recipes list in "Pragmatic Version
Control with CVS" by Dave Thomas and Andy Hunt (see
L<http://www.pragmaticprogrammer.com/starter_kit/vcc/index.html>).

=head2 UTILITY METHODS

=over 4

=item new ( [ CONFIG_ITEMS ] )

Creates an instance of Cvs::Simple.

CONFIG_ITEMS is a hash of configuration items.  Recognised configuration items are:

=over 8

=item cvs_bin

=item external

=item callback

=back

See the method descriptions below for details of these.   If none are
specified, CVS::Simple will choose some sensible defaults.

=item callback ( CMD, CODEREF )

Specify a function pointed to by CODEREF to be executed for every line output
by CMD.  

Permitted values of CMD are C<All> (executed on every line of
output), C<add>, C<commit>, C<checkout>, C<diff>, C<update>.  CMD is also
permitted to be undef, in which case, it will be assumed to be C<All>.

cvs_cmd passes two arguments to callbacks:  the actual command called, and the
line returned by CVS.

See the tests for examples of callbacks.

=item 

=item unset_callback ( CMD )

Remove the callback set for CMD.

=item cvs_bin ( PATH ) 

Specifies the location and name of the CVS binary.  Default to
C</usr/bin/cvs>.

=item cvs_cmd ( )

cvs_cmd() does the actual work of calling the equivalent CVS command.  If any
callbacks have been set, they will be executed for every line received from
the command.  If no callbacks have been set, all output is to STDOUT.

=item external( REPOSITORY )

Specify an "external" repository.  This can be a genuinely remote
repository in C<:ext:user@repos.tld:/path/to/cvsroot> format, or an
alternative repository on the local host.  This will be passed to the C<-d>
CVS global option.

=back

=head2 CVS METHODS 

=over 4

=item add     ( FILE1, [ .... , FILEx ] )

=item add_bin ( FILE1, [ .... , FILEx ] )

Add a file or files to the repository; equivalent to C<cvs add file1, ....>,
or C<cvs add -kb file1, ...> in the case of add_bin().

=item co ( TAG, MODULE )

  Alias for checkout()

=item checkout ( MODULE )

=item checkout ( TAG, MODULE )

  Note that co() can be used as an alias for checkout().

=item ci

  Alias for commit().

=item commit ( )

=item commit ( FILELIST_ARRAYREF )

=item commit ( TAG )

=item commit ( TAG, FILELIST_ARRAYREF )

These are the equivalent of C<cvs commit -m "">, C<cvs commit -m "" file1, file2, ...., fileN>, C<cvs commit -r TAG -m ""> and C<cvs commit -r TAG -m "" file1, file2, ....,
fileN> respectively.

Note that ci() can be used as an alias for commit().

=item diff ( FILE_OR_DIR )

=item diff ( TAG1, TAG2, FILE_OR_DIR )

FILE_OR_DIR is a single file, or a directory, in the sandbox.

Performs context diff: equivalent to C<cvs diff -c FILE_OR_DIR> or C<cvs
diff -c -rTAG1 -rTAG2 FILE_OR_DIR>.

=item merge ( OLD_REV, NEW_REV, FILENAME )

This is the equivalent of C<cvs -q update -jOLD_REV -jNEW_REV FILENAME>.  Note
for callback purposes that this is actually an update().

=item backout ( CURRENT_REV, REVERT_REV, FILENAME )

=item undo ( CURRENT_REV, REVERT_REV, FILENAME )

Reverts from CURRENT_REV to REVERT_REV.  Equivalent to C<cvs update
-jCURRENT_REV -jREVERT_REV FILENAME>.

Note that backout() can be used as an alias for undo().

Note that for callback purposes this is actually an update().

=item upd 

  Alias for update().

=item update ( )

=item update ( FILE1, [ ...., FILEx ] );

Equivalent to C<cvs -q update -d> and C<cvs -d update file1, ..., filex>.

Note that updates to a specific revision (C<-r>) and sticky-tag resets (C<-A>) are not currently supported.

Note that upd() is an alias for update().

=item up2date ( )

Short-hand for C<cvs -nq update -d>.

=item status ( )

=item status( file1 [, ..., ... ] )

Equivalent to C<cvs status -v>.

=back

=head2 EXPORT

None by default.

=head1 LIMITATIONS AND CAVEATS

=over 4

=item 1. Note that C<Cvs::Simple> carries out no input validation; everything is
passed on to CVS.  Similarly, the caller will receive no response on the
success (or otherwise) of the transaction, unless appropriate callbacks have
been set.

=item 2. The C<cvs_cmd> method is quite simplistic; it's basically a pipe from
the equivalent CVS command line (with STDERR redirected).  If a more
sophisticated treatment, over-ride C<cvs_cmd>, perhaps with something based on
C<IPC::Run> (as the L<Cvs> package does).

=item 3. This version of C<Cvs::Simple> has been developed against cvs version
1.11.19.  Command syntax may differ in other versions of cvs, and
C<Cvs::Simple> method calls may fail in unpredictable ways if other versions
are used.   Cross-version compatibiility is something I intend to address in a
future version.

=item 4. The C<diff>, C<merge>, and C<undo> methods lack proper tests.  More
tests are required generally.

=back

=head1 SEE ALSO

cvs(1), L<Cvs>, L<VCS::Cvs>

=head1 AUTHOR

Stephen Cardie, E<lt>stephenca@ls26.netE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2007,2008 by Stephen Cardie

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.8.8 or,
at your option, any later version of Perl 5 you may have available.

=cut



( run in 0.806 second using v1.01-cache-2.11-cpan-d8267643d1d )