Created
September 18, 2010 15:46
-
-
Save melo/585775 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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