#!/usr/local/bin/perl -w =head1 NAME fi_comment_spec.pl - form-in trigger that creates a comments file for a spec form. =head1 SYNOPSYS B trigger installation entry for protection table: record_comments form-in protect "//perl //fi_comment_spec.pl %formfile% //" =head1 DESCRIPTION This trigger script together with its matching form-out partner allows the commenting of spec forms such as the protection table, transparently for the user (i.e. without having to invoke I from a wrapper script). Comment lines start with the B<#> char, which can be preceeded by blank spaces. Comments will be recorded even if Perforce returns that the spec was not changed. =head1 LIMITATIONS This works on the principle that each spec line is unique, which is often (but not necessarily always) the case. If identical lines are found, it will be "first come first served". Only one comment per line is permitted for now. =head1 NOTES This script uses I which is usually bundled with Perl. =head1 AUTHOR Guillaume Barthelemy >, June 2008. =cut use strict; use Data::Dumper; my $form = shift; my $comments_path = shift; my $comment; my $body = 0; my %comments = (); # slurp protection table form open FORM, "<", $form or die ("Trigger couldn't read from temporary file $form.\n$!"); my @lines =
; close FORM; # build hash foreach my $line (@lines) { chomp $line; if ($body) { if ($line =~ /^(\s*#.*)$/) { $comment = $1; # Ignore blank lines } elsif ($line !~ /^\s*$/) { $comments{$line} = $comment if ($comment); $comment = ""; } } else { # Ignore spec header $body = $line !~ /^#/; } } open COMMENT, ">", $comments_path or die ("Trigger couldn't write comments file $comments_path.\n$!"); print COMMENT Data::Dumper->Dump([\%comments], ["comments"]), $/; close COMMENT; exit 0;