Arch::DiffParser(3pm)

πŸ“¦ version 0.5.2, in ubuntu jammy

πŸ’– Arch::DiffParser πŸ’–

okay bestie, so this is Arch::DiffParser, a Perl thingy (from the User Contributed Perl Documentation, no big deal) and its whole vibe is: parse a file's diff and perform some manipulations. that's it. that's the girl. πŸŽ€


✨ NAME ✨

Arch::DiffParser β€” parse file's diff and perform some manipulations. periodt. πŸ’…


✨ SYNOPSIS ✨

okay so here's the lil demo, literally just copy it bestie:

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;

no cap, that's the whole plot. πŸ¦‹


✨ DESCRIPTION ✨

so basically this class provides a limited functionality to parse a single file diff in unified format. and yeah β€” multiple diffs may be parsed sequentially, she can hold it down like that. 😌

but listen: the parsed data is stored for the last diff, and it gets replaced on the following parse. so don't come crying to me when your old diff is gone, that's just how she moves. πŸ’€


✨ METHODS ✨

the following class methods are available, bestie:

new, parse, parse_file, content, lines, filename1, filename2, mtime1, mtime2, hunks, changes.

let's go through them one by one, i got you 🫢


πŸ’« new

Construct the Arch::DiffParser instanse.

(yes the original says "instanse", iconic typo, we stan, not fixing it πŸ’…)


πŸ’« parse diff_content

Parse the diff_content and store its parsed data. that's the whole job. slay. ✨


πŸ’« parse_file diff_filename

Like parse, but read the diff_content from diff_filename. same energy, just from a file instead. πŸŽ€


πŸ’« diff_data

Return a hashref containing certain parsed data. Die if called before any parse methods. like, do NOT try her before you've parsed anything, she will end you. 😭

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 ]

okay and lemme explain the terminology so you're not lost:

  • 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.

iykyk. 🧚


πŸ’« lines, filename1, filename2, mtime1, mtime2, hunks, changes

These methods are just shortcuts for diff_data->{method}. lazy girl summer, but make it efficient. πŸ’œ


πŸ’« 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. so cute, customizing your lil paths. 🌸


πŸ’« 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. so like… do not expect it to work bestie, she said what she said. πŸ’€

πŸ› BUGS πŸ›

No support for newlines in source file names yet. so if your filename has a newline in it… girl. πŸ™ˆ


πŸ‘‘ AUTHORS πŸ‘‘

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


🌈 SEE ALSO 🌈

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


and that's the whole page, bestie! this lil beauty is from perl v5.20.2, dated 2005-03-09, and it lives under Arch::DiffParser(3pm). go forth and parse those diffs, you main character. πŸ¦‹βœ¨πŸ’–

πŸ“¦ where this page comes from