| 1 | package Diff::LibXDiff; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | =head1 NAME | ||||||||||
| 7 | |||||||||||
| 8 | Diff::LibXDiff - Calculate a diff with LibXDiff (via XS) | ||||||||||
| 9 | |||||||||||
| 10 | =head1 VERSION | ||||||||||
| 11 | |||||||||||
| 12 | Version 0.05 | ||||||||||
| 13 | |||||||||||
| 14 | =cut | ||||||||||
| 15 | |||||||||||
| 16 | 2 | our $VERSION = '0.05'; | |||||||||
| 17 | |||||||||||
| 18 | =head1 SYNOPSIS | ||||||||||
| 19 | |||||||||||
| 20 | use Diff::LibXDiff; | ||||||||||
| 21 | |||||||||||
| 22 | my $string1 = <<_END_ | ||||||||||
| 23 | apple | ||||||||||
| 24 | banana | ||||||||||
| 25 | cherry | ||||||||||
| 26 | _END_ | ||||||||||
| 27 | |||||||||||
| 28 | my $string2 = <<_END_ | ||||||||||
| 29 | apple | ||||||||||
| 30 | grape | ||||||||||
| 31 | cherry | ||||||||||
| 32 | lime | ||||||||||
| 33 | _END_ | ||||||||||
| 34 | |||||||||||
| 35 | my $diff = Diff::LibXDiff->diff( $string1, $string2 ) | ||||||||||
| 36 | my $bin_diff = Diff::LibXDiff->bdiff( $bin_string1, $bin_string2 ) | ||||||||||
| 37 | |||||||||||
| 38 | # $diff is ... | ||||||||||
| 39 | |||||||||||
| 40 | @@ -1,3 +1,4 @@ | ||||||||||
| 41 | apple | ||||||||||
| 42 | -banana | ||||||||||
| 43 | +grape | ||||||||||
| 44 | cherry | ||||||||||
| 45 | +lime | ||||||||||
| 46 | |||||||||||
| 47 | =head1 DESCRIPTION | ||||||||||
| 48 | |||||||||||
| 49 | Diff::LibXDiff is a binding of LibXDiff (L<http://www.xmailserver.org/xdiff-lib.html>) to Perl via XS | ||||||||||
| 50 | |||||||||||
| 51 | LibXDiff is the basis of the diff engine for git | ||||||||||
| 52 | |||||||||||
| 53 | =cut | ||||||||||
| 54 | |||||||||||
| 55 | 2 | require Exporter; | |||||||||
| 56 | 2 | require DynaLoader; | |||||||||
| 57 | |||||||||||
| 58 | 2 | ▶ | use Carp::Clan; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 59 | |||||||||||
| 60 | 2 | our @ISA = qw/Exporter DynaLoader/; | |||||||||
| 61 | 2 | our @EXPORT_OK = qw//; | |||||||||
| 62 | |||||||||||
| 63 | 2 | bootstrap Diff::LibXDiff $VERSION; | |||||||||
| 64 | |||||||||||
| 65 | =head1 METHODS | ||||||||||
| 66 | |||||||||||
| 67 | =head2 $diff = Diff::LibXDiff->diff( $string1, $string2 ) | ||||||||||
| 68 | |||||||||||
| 69 | Calculate the textual diff of $string1 and $string2 and return the result as a string | ||||||||||
| 70 | |||||||||||
| 71 | =head2 $patched = Diff::LibXDiff->patch( $original, $patch ) | ||||||||||
| 72 | |||||||||||
| 73 | =head2 ( $patched, $rejected ) = Diff::LibXDiff->patch( $original, $patch ) | ||||||||||
| 74 | |||||||||||
| 75 | Calculate the patched string given an original string and a patch string | ||||||||||
| 76 | |||||||||||
| 77 | If the patching algorithm cannot place a hunk, it will return a second "rejected" result (if called in list context) | ||||||||||
| 78 | |||||||||||
| 79 | =head2 $bdiff = Diff::LibXDiff->bdiff( $bin1, $bin2 ) | ||||||||||
| 80 | |||||||||||
| 81 | Calculate the binary diff of $bin1 and $bin2 and return result as a string | ||||||||||
| 82 | |||||||||||
| 83 | =head2 $bpatched = Diff::LibXDiff->bpatch( $original, $patch ) | ||||||||||
| 84 | |||||||||||
| 85 | Calculate the patched binary given an original string and a patch string | ||||||||||
| 86 | |||||||||||
| 87 | =cut | ||||||||||
| 88 | |||||||||||
| 89 | 2 | ▶ | sub diff { | ||||||||
|
Subroutine
diff: called CC=7 SCAR=20.6
Pod
documented
| |||||||||||
| 90 | 2 | my $self = shift; | |||||||||
| 91 | 2 | my ($string1, $string2) = @_; | |||||||||
| 92 | |||||||||||
| 93 | 2 | ▶ | croak "string1 not defined" unless defined $string1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 94 | 2 | ▶ | croak "string2 not defined" unless defined $string2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | 2 | ▶ | croak "string1 isn't a string" if ref $string1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 96 | 2 | ▶ | croak "string2 isn't a string" if ref $string2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 97 | |||||||||||
| 98 | 2 | my $result = _xdiff( $string1, $string2 ); | |||||||||
| 99 | |||||||||||
| 100 | 2 | my @error = @{ $result->{error} }; | |||||||||
| 101 | |||||||||||
| 102 | 2 | ▶ | croak join '', "Unable to process the diff of string1 & string2: ", join ', ', @error if @error; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 103 | |||||||||||
| 104 | return wantarray ? | ||||||||||
| 105 | ( $result->{result} ) : | ||||||||||
| 106 | $result->{result} | ||||||||||
| 107 | 2 | ▶ | ; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 108 | } | ||||||||||
| 109 | |||||||||||
| 110 | 1 | ▶ | sub bdiff { | ||||||||
|
Subroutine
bdiff: called CC=7 SCAR=20.6
Pod
documented
| |||||||||||
| 111 | 1 | my $self = shift; | |||||||||
| 112 | 1 | my ($string1, $string2) = @_; | |||||||||
| 113 | |||||||||||
| 114 | 1 | ▶ | croak "String1 not defined" unless defined $string1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 115 | 1 | ▶ | croak "String2 not defined" unless defined $string2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 116 | 1 | ▶ | croak "string1 isn't a string" if ref $string1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 117 | 1 | ▶ | croak "string2 isn't a string" if ref $string2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 118 | |||||||||||
| 119 | 1 | my $result = _xbdiff( $string1, $string2 ); | |||||||||
| 120 | |||||||||||
| 121 | 1 | my @error = @{ $result->{error} }; | |||||||||
| 122 | |||||||||||
| 123 | 1 | ▶ | croak join '', "Unable to process the diff of string1 & string2: ", join ', ', @error if @error; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 124 | |||||||||||
| 125 | return wantarray ? | ||||||||||
| 126 | ( $result->{result} ) : | ||||||||||
| 127 | $result->{result} | ||||||||||
| 128 | 1 | ▶ | ; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 129 | } | ||||||||||
| 130 | |||||||||||
| 131 | 2 | ▶ | sub patch { | ||||||||
|
Subroutine
patch: called CC=7 SCAR=20.6
Pod
documented
| |||||||||||
| 132 | 2 | my $self = shift; | |||||||||
| 133 | 2 | my ($string1, $string2) = @_; | |||||||||
| 134 | |||||||||||
| 135 | 2 | ▶ | croak "string1 not defined" unless defined $string1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 136 | 2 | ▶ | croak "string2 not defined" unless defined $string2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 137 | 2 | ▶ | croak "string1 isn't a string" if ref $string1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 138 | 2 | ▶ | croak "string2 isn't a string" if ref $string2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 139 | |||||||||||
| 140 | 2 | my $result = _xpatch( $string1, $string2 ); | |||||||||
| 141 | |||||||||||
| 142 | 2 | my @error = @{ $result->{error} }; | |||||||||
| 143 | |||||||||||
| 144 | 2 | ▶ | croak join '', "Unable to process the patch of string1 & string2: ", join ', ', @error if @error; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 145 | |||||||||||
| 146 | return wantarray ? | ||||||||||
| 147 | ( $result->{result}, $result->{rejected_result} ) : | ||||||||||
| 148 | 2 | ▶ | $result->{result}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 149 | |||||||||||
| 150 | } | ||||||||||
| 151 | |||||||||||
| 152 | 1 | ▶ | sub bpatch { | ||||||||
|
Subroutine
bpatch: called CC=7 SCAR=20.6
Pod
documented
| |||||||||||
| 153 | 1 | my $self = shift; | |||||||||
| 154 | 1 | my ($string1, $string2) = @_; | |||||||||
| 155 | |||||||||||
| 156 | 1 | ▶ | croak "string1 not defined" unless defined $string1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 157 | 1 | ▶ | croak "string2 not defined" unless defined $string2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 158 | 1 | ▶ | croak "string1 isn't a string" if ref $string1; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 159 | 1 | ▶ | croak "string2 isn't a string" if ref $string2; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 160 | |||||||||||
| 161 | 1 | my $result = _xbpatch( $string1, $string2 ); | |||||||||
| 162 | |||||||||||
| 163 | 1 | my @error = @{ $result->{error} }; | |||||||||
| 164 | |||||||||||
| 165 | 1 | ▶ | croak join '', "Unable to process the patch of string1 & string2: ", join ', ', @error if @error; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 166 | |||||||||||
| 167 | return wantarray ? | ||||||||||
| 168 | ( $result->{result}, $result->{rejected_result} ) : | ||||||||||
| 169 | 1 | ▶ | $result->{result}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 170 | } | ||||||||||
| 171 | |||||||||||
| 172 | =head1 AUTHOR | ||||||||||
| 173 | |||||||||||
| 174 | Robert Krimen, C<< <rkrimen at cpan.org> >> | ||||||||||
| 175 | |||||||||||
| 176 | =head1 SEE ALSO | ||||||||||
| 177 | |||||||||||
| 178 | L<http://www.xmailserver.org/xdiff-lib.html> | ||||||||||
| 179 | |||||||||||
| 180 | L<Algorithm::Diff> | ||||||||||
| 181 | |||||||||||
| 182 | =head1 BUGS | ||||||||||
| 183 | |||||||||||
| 184 | Please report any bugs or feature requests to C<bug-diff-libxdiff at rt.cpan.org>, or through | ||||||||||
| 185 | the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Diff-LibXDiff>. I will be notified, and then you'll | ||||||||||
| 186 | automatically be notified of progress on your bug as I make changes. | ||||||||||
| 187 | |||||||||||
| 188 | |||||||||||
| 189 | |||||||||||
| 190 | |||||||||||
| 191 | =head1 SUPPORT | ||||||||||
| 192 | |||||||||||
| 193 | You can find documentation for this module with the perldoc command. | ||||||||||
| 194 | |||||||||||
| 195 | perldoc Diff::LibXDiff | ||||||||||
| 196 | |||||||||||
| 197 | |||||||||||
| 198 | You can also look for information at: | ||||||||||
| 199 | |||||||||||
| 200 | =over 4 | ||||||||||
| 201 | |||||||||||
| 202 | =item * RT: CPAN's request tracker | ||||||||||
| 203 | |||||||||||
| 204 | L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Diff-LibXDiff> | ||||||||||
| 205 | |||||||||||
| 206 | =item * AnnoCPAN: Annotated CPAN documentation | ||||||||||
| 207 | |||||||||||
| 208 | L<http://annocpan.org/dist/Diff-LibXDiff> | ||||||||||
| 209 | |||||||||||
| 210 | =item * CPAN Ratings | ||||||||||
| 211 | |||||||||||
| 212 | L<http://cpanratings.perl.org/d/Diff-LibXDiff> | ||||||||||
| 213 | |||||||||||
| 214 | =item * Search CPAN | ||||||||||
| 215 | |||||||||||
| 216 | L<http://search.cpan.org/dist/Diff-LibXDiff/> | ||||||||||
| 217 | |||||||||||
| 218 | =back | ||||||||||
| 219 | |||||||||||
| 220 | |||||||||||
| 221 | =head1 ACKNOWLEDGEMENTS | ||||||||||
| 222 | |||||||||||
| 223 | |||||||||||
| 224 | =head1 COPYRIGHT & LICENSE | ||||||||||
| 225 | |||||||||||
| 226 | Copyright 2009 Robert Krimen, all rights reserved. | ||||||||||
| 227 | |||||||||||
| 228 | This program is free software; you can redistribute it and/or modify it | ||||||||||
| 229 | under the same terms as Perl itself. | ||||||||||
| 230 | |||||||||||
| 231 | |||||||||||
| 232 | =cut | ||||||||||
| 233 | |||||||||||
| 234 | 2 | 1; # End of Diff::LibXDiff | |||||||||