=head1 NAME

MT::Plugins::SHA1 - MoveableType plugin to calculate SHA1 Digest of Body

=cut

package MT::Plugins::SHA1;

=head1 SYNOPSIS

Once installed in your MovableType plugins directory, the following
new tags will be available for use within templates:

<MTSha1>some text</MTSha1>

=head1 REQUIRES

 MovableType 2.6 or higher
 Digest::SHA1

=head1 DESCRIPTION

=head2 MTSha1

The <MTSha1></MTSha1> tag will calculate a SHA1 Sum for the enclosed body.

=cut

use strict;
use warnings;

use MT 2.6;
use MT::Template::Context;
BEGIN {
	no warnings 'numeric';
	our $NAME		= "MTSha1";
	our $VERSION	= '0.001';
	our $plugin_data	= {
			name		=> "${NAME}, v${VERSION}",
			description => 'Calculates SHA1 Sum of body',
			doc_link	=> 'http://www.picklematrix.net/'
		};
	
	if ($MT::VERSION >= 3.0) {
		require MT::Plugin;
		MT::Plugin->import();
		my $plugin	= new MT::Plugin($plugin_data);
		MT->add_plugin($plugin);
	}
}

use Digest::SHA1 qw(sha1_hex);

our $debug		= 0;
use Data::Dumper;

######################################################################

MT::Template::Context->add_container_tag( Sha1 => sub {
	my $warnings;
	local($SIG{__WARN__})	= sub { $warnings .= $_[0] };
	my $ctx		= shift;
	my $args	= shift;
    my $builder = $ctx->stash('builder');
    my $tokens = $ctx->stash('tokens');
    defined(my $out = $builder->build($ctx, $tokens))
      or return $ctx->error($builder->errstr);
    return sha1_hex($out);
} );

######################################################################

1;

__END__

=head1 SEE ALSO

 L<MT::Plugin>
 L<Digest::SHA1>

=head1 KNOWN BUGS

None.

=head1 TODO

None.

=head1 LICENSE

Copyright (c) 2004 Seth Ladd. All rights reserved. This program is free
software; you can redistribute it and/or modify it under the same terms as Perl
itself.

=head1 AUTHOR

 Seth Ladd <seth@picklematrix.net>

=cut
