The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Mojo::File::Role::Digest - A role for Mojo::File to calculate digests

SYNOPSIS

    # single file
    use Mojo::File 'path';
    my $file = path($path)->with_roles('+Digest');

    # modified file class
    use Mojo::File;
    my $class = Mojo::File->with_roles('+Digest');
    my $file = $class->new($path);

    $file->md5_sum;
    $file->quickxor_hash;  # requires Digest::QuickXor
    $file->sha1_sum;
    $file->sha256_sum;

DESCRIPTION

Mojo::File::Role::Digest is a role for Mojo::File to calculate MD5, SHA1, SHA256, and QuickXor digests.

If the path isn't an existing file, all methods return an empty string ''.

APPLY ROLE

    use Mojo::File 'path';

    my $file             = path($path);
    my $file_with_digest = $file->with_roles('+Digest');

Apply to a single Mojo::File object. See "with_roles" in Mojo::Base.

    use Mojo::File;
    my $class = Mojo::File->with_roles('+Digest');

    my $file1 = $class->new($path1);
    my $file2 = $class->new($path2);

Create a modified file class with applied digest role.

METHODS

md5_sum

    $string = $file->md5_sum;

Returns the MD5 sum of the file in hexadecimal form. See "hexdigest" in Digest::MD5.

quickxor_hash

    $string = $file->quickxor_hash;

Returns the base64 encoded QuickXorHash of the file. See "b64digest" in Digest::QuickXor. Requires Digest::QuickXor 0.03 or higher.

sha1_sum

    $string = $file->sha1_sum;

Returns the SHA1 sum of the file in hexadecimal form. See "hexdigest" in Digest::SHA.

sha256_sum

    $string = $file->sha256_sum;

Returns the SHA256 sum of the file in hexadecimal form. See "hexdigest" in Digest::SHA.

AUTHOR & COPYRIGHT

© 2019–2020 by Tekki (Rolf Stöckli).

This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.

SEE ALSO

Mojo::File, Mojo::Base, Role::Tiny, Digest::MD5, Digest::QuickXor, Digest::SHA.