Perl::Signature - Generate functional signatures for Perl source code
In early beta, PPI introduced the concept of "Document Normalization" into the core. It had previously only been implemented "behind the scenes" as part of Perl::Compare.
Unfortunately, there isn't a whole lot of things you can do with a PPI::Document::Normalized object. It's a giant twisty mass of objects and perl structure, and not very practical for long term storage.
Perl::Signature implements the idea of a "functional signature" for Perl documents, implemented in a similar way to Object::Signature.
The normalized document is serialized to a string with Storable, then this string is converted into a MD5 hash, producing a single short string which represents the functionality of the Perl document.
This signature can then be stored and transfered easily, and at any later point the signature can be regenerated for the file to ensure that it has not changed (functionally).
Perl::Signature is relatively sensitive to change.
Primarily, this is because PPI::Normal is biased towards false negative comparison. (Avoiding false "these are the same" by accepting a number of false "these are not the same" results).
In addition, the serialization of Storable is not assured to use identical file formats across versions.
In short, you should assume that a signature is valid at best for only as long as the PPI and Storable versions are the same, and at worst only for the current process.
PPI::Signature provides two sets of methods. A set of
The file_signature static method takes a filename and produces a signature for the file.
file_signature
Returns a 32 character hexidecimal MD5 signature, or undef on error.
undef
The source_signature static method generates a signature for any arbitrary Perl source code, which can be passed as either a raw string, or a reference to a SCALAR containing the code.
source_signature
The document_signature method takes a PPI::Document object and generates a signature for it.
document_signature
As well as static methods for generatic signatures, Perl::Signature also provides a simple way to create signature objects for a particular file.
This makes it relatively easy to see if a file has changed
The new constructor takes as argument the name of a file, and creates an object that remembers current signature of the file.
new
The file accessor returns the name of the file that a Perl::Signature object is set to.
file
The current method returns the current signature for the file.
current
The original accessor returns the original signature at the time of the creation of the object.
original
The changed method checks to see if the signature has changed since the object was created.
changed
Returns true if the file has been (functionally) changed, false if not, or undef on error.
The unchanged method checks to ensure that the signature has not changed since the object was created.
unchanged
Returns true if the file is (functionally) unchanged, false if it has changed, or undef on error.
All bugs should be filed via the CPAN bug tracker at
http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Perl-Signature
For other issues, or commercial enhancement or support, contact the author.
Adam Kennedy <adamk@cpan.org>
http://ali.as/, PPI
Copyright 2004 - 2008 Adam Kennedy.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
The full text of the license can be found in the LICENSE file included with this module.
To install Perl::Signature, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Perl::Signature
CPAN shell
perl -MCPAN -e shell install Perl::Signature
For more information on module installation, please visit the detailed CPAN module installation guide.