Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Perl/.funcignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git*
.vscode
local.settings.json
test
14 changes: 14 additions & 0 deletions Perl/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

# Azure Functions artifacts
bin
obj
appsettings.json
local.settings.json

# Azurite artifacts
__blobstorage__
__queuestorage__
__azurite_db*__.json

# Strawberry
Strawberry/*
20 changes: 20 additions & 0 deletions Perl/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Azure Functions custom handler in Perl

The samples available in this folder demonstrate how to implement a [custom handler](https://docs.microsoft.com/azure/azure-functions/functions-custom-handlers).

Example functions featured in this repo include:

| Name | Trigger | Input | Output |
|------|---------|-------|--------|
| [SimpleHttpTrigger](../../../tree/master/Perl/SimpleHttpTrigger) | HTTP | n/a | n/a |

## Configuration

The *local.settings-example.json* is provided to show what values the app is expecting to read from environment variables. Make a copy of *local.settings-example.json* and rename it *local.settings.json* and replace any values that begin with "**YOUR_**" with your values.

## Pre-reqs

- Perl (Strawberry) : https://strawberryperl.com/
- Put the Strawberry packages which is included in perl.exe to under `Strawberry` folder after download.
- Windows **ONLY**.
- Azure Functions Core Tools
19 changes: 19 additions & 0 deletions Perl/SimpleHttpTrigger/function.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"bindings": [
{
"authLevel": "anonymous",
"type": "httpTrigger",
"direction": "in",
"name": "req",
"methods": [
"get",
"post"
]
},
{
"type": "http",
"direction": "out",
"name": "res"
}
]
}
22 changes: 22 additions & 0 deletions Perl/host.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"version": "2.0",
"logging": {
"applicationInsights": {
"samplingSettings": {
"isEnabled": true,
"excludedTypes": "Request"
}
}
},
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle",
"version": "[1.*, 2.0.0)"
},
"customHandler": {
"description": {
"defaultExecutablePath": "Strawberry/perl/bin/perl.exe",
"arguments": ["src/main.pl"]
},
"enableForwardingHttpRequest": true
}
}
8 changes: 8 additions & 0 deletions Perl/local.settings-example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "YOUR_STORAGE_CONNECTION_STRING",
"FUNCTIONS_WORKER_RUNTIME": "custom"
}
}

23 changes: 23 additions & 0 deletions Perl/src/main.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!usr/bin/env perl
use HTTP::Daemon;
use HTTP::Status;
use Env;

my $port = $ENV{"FUNCTIONS_CUSTOMHANDLER_PORT"};
my $function_name = "SimpleHttpTrigger";
my $d = HTTP::Daemon->new(LocalAddr => "127.0.0.1", LocalPort => $port ) || die;
print "Please contact me at: <URL:", $d->url, ">\n";

while (my $c = $d->accept) {
while (my $r = $c->get_request) {
if ($r->method eq "GET" and $r->uri->path eq "/api/" . $function_name) {
print "Perl is running on Azure Functions";
$c->send_response( HTTP::Response->new(200, "OK", undef, "Perl is running on Azure Functions\n") );
}
else {
$c->send_error(RC_FORBIDDEN)
}
}
$c->close;
undef($c);
}