Skip to content

Instantly share code, notes, and snippets.

@melo
Created September 18, 2010 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save melo/585775 to your computer and use it in GitHub Desktop.
Save melo/585775 to your computer and use it in GitHub Desktop.
package Tarpipe::Connector::Digest;
use strict;
use warnings;
use Plack::App::Tarpipe;
use Digest::SHA1 qw(sha1_hex);
use Digest::MD5 qw(md5_hex);
## Definition of the connector
## GET uri will return the proper XML
connector
name 'Crypto Digest',
title 'Create crypto Digests for content',
uri 'http://connectors.simplicidade.org/digest/c/',
version 1,
service { uri 'http://connectors.simplicidade.org/digest/' },
input 'text' => {label 'Text', mime 'text/*', required},
input 'algorithm' => {label 'Algorithm', mime 'text/plain'},
output 'digest' => {label 'Digest', mime 'text/plain'};
## gets called for each request
## $inputs is a hashref with all the input fields
## must return $output, a hashref with all the output fields
sub execute {
my ($self, $inputs) = @_;
my $text = $inputs->{text};
my $algo = $inputs->{algorithm} || 'sha1'; ## defaults to sha1
my $outputs;
if ($algo eq 'md5') {
$output->{digest} = md5_hex($text);
}
else {
$output->{digest} = sha1_hex($text);
}
return $outputs;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment