---
name: "Arch::DiffParser"
section: "3pm"
platform: "linux"
package: "libarch-perl"
version: "0.5.2-2"
release: "Debian 11 (Bullseye)"
platforms: ["linux"]
url: "https://new.carta.tech/Arch::DiffParser"
---

# Arch::DiffParser(3pm)

parse file's diff and perform some manipulations

## NAME

Arch::DiffParser - parse file's diff and perform some manipulations

## SYNOPSIS

```
    use Arch::DiffParser;
    my $dp = Arch::DiffParser->new;
    # usable for "annotate" functionality
    my $changes = $dp->parse_file("f.diff")->changes;
    $dp->parse($diff_content);
    $dp->parse("--- f1.c\t2005-02-26\n+++ f2.c\t2005-02-28\n...");
    # prints "f1.c, f2.c"
    printf "%s, %s\n", $dp->filename1, $dp->filename2;
    # enclose lines in <span class="patch_{mod,orig,line,add,del}">
    my $html = $dp->markup_content;
```

## DESCRIPTION

This class provides a limited functionality to parse a single file diff in unified format. Multiple diffs may be parsed sequentially. The parsed data is stored for the last diff, and is replaced on the following parse.

## METHODS

The following class methods are available:

**new**, **parse**, **parse\_file**, **content**, **lines**, **filename1**, **filename2**, **mtime1**, **mtime2**, **hunks**, **changes**.

- **new**

  Construct the `"Arch::DiffParser"` instanse.

- **parse** *diff\_content*

  Parse the *diff\_content* and store its parsed data.

- **parse\_file** *diff\_filename*

  Like **parse**, but read the *diff\_content* from *diff\_filename*.

- **diff\_data**

  Return hashref containing certain parsed data. Die if called before any **parse** methods. The keys are: "lines", "filename1", "filename2", "mtime1", "mtime2", "hunks", "changes".

  The value of "hunks" and "changes" is arrayref of arrayrefs with 5 elements: \[ line-number-1, num-lines-1, line-number-2, num-lines-2, "lines"-index \].

  A "hunk" describes a set of lines containing some combination of unmodified, deleted and added lines, a "change" describes an inter-hunk atom that only contains zero or more deleted lines and zero or more added lines.

- **lines**

  - **filename1**

  - **filename2**

  - **mtime1**

  - **mtime2**

  - **hunks**

  - **changes**

  These methods are just shortcuts for **diff\_data**-\>{*method*}.

- **content** \[*%args*\]

  Return content of the last diff.

  *%args* keys are "fileroot1" and "fileroot2"; if given, these will replace the subdirs "orig" and "mod" that arch usually uses in the filepaths.

- **markup\_content** \[*%args*\]

  Like **content**, but every non-context line is enclosed into markup \<span class="patch\_*name*"\>line\</span\>, where *name* is one of "orig" (filename1), "mod" (filename2), "line" (hunk linenums), "add" (added), del (deleted).

  Not implemented yet.

## BUGS

No support for newlines in source file names yet.

## AUTHORS

Mikhael Goikhman (migo@homemail.com--Perl-GPL/arch-perl--devel).

## SEE ALSO

For more information, see Text::Diff::Unified, Algorithm::Diff.
