Newcomen

Description A static content generator.
Newcomen > Perl Modules > Newcomen::Util
Source

Index


NAME ^

Newcomen::Util - Utility functions.

SYNOPSIS ^

use Newcomen::Util;

if (Newcomen::Util::is_a ($page, 'Newcomen::Page')) {
   # do something...
}

my $checksum = Newcomen::Util::data_sha1 ($data);

DESCRIPTION ^

This package provides miscellaneous utility functions. Note that all functions may be imported into the package using Newcomen::Util:

use Newcomen::Util qw( is_a data_sha1 );

No function is exported by default.

FUNCTIONS ^

is_a

Toggle source:   is_a

sub is_a {

   my $var = shift;
   my $cls = shift;

   defined $var && Scalar::Util::blessed $var && $var -> isa ($cls);

}
if (Newcomen::Util::is_a ($page, 'Newcomen::Page')) {
   # do something...
}

This function will return a true value if the variable supplied as first parameter is an instance of the class supplied by its full name as the second parameter, a false value otherwise.

data_sha1

Toggle source:   data_sha1

sub data_sha1 {

   local $Data::Dumper::Indent   = 0;
   local $Data::Dumper::Pair     = '=>',
   local $Data::Dumper::Purity   = 1;
   local $Data::Dumper::Sortkeys = 1;
   local $Data::Dumper::Terse    = 1;

   return Digest::SHA::sha1_hex (Data::Dumper::Dumper (shift));

}
my $checksum = Newcomen::Util::data_sha1 ($data);

This function expects one parameter, usually a hashref or arrayref. It will serialize the data structure using Data::Dumper, and calculate the SHA-1 hash of the serialized data. The function will return the hexadecimal representation of the hash.

Note: Results will only be reliable if the data structure does not contain anything else than simple scalar values, especially any blessed objects should be avoided!

VERSION ^

This is version 2014052501.

AUTHOR ^

Stefan Goebel - newcomen {at} subtype {dot} de

COPYRIGHT AND LICENSE ^

Copyright 2013-2014 Stefan Goebel.

This file is part of Newcomen.

Newcomen is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the license, or (at your option) any later version.

Newcomen is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with Newcomen. If not, see <http://www.gnu.org/licenses/>.