From 87aa81fef4b5fd359e1ce666b7db846663520e04 Mon Sep 17 00:00:00 2001 From: Chris Date: Mon, 1 Oct 2018 22:07:16 +0100 Subject: [PATCH] Start adding support for recipe slugs --- blocks/ORB/View.pm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/blocks/ORB/View.pm b/blocks/ORB/View.pm index 2019f1b..a7f457c 100644 --- a/blocks/ORB/View.pm +++ b/blocks/ORB/View.pm @@ -25,6 +25,20 @@ use experimental qw(smartmatch); use Regexp::Common qw(URI); use v5.14; +## @method private $ _resolve_recipe_name($rid) +# Given a recipe name, locate the recipe with that name if possible. +# If rid is purely numeric, this assumes it's already just an ID and +# returns it as-is, otherwise this will search for the recipe and +# return the ID of the recipe, or undef if it can't be found. +sub _resolve_recipe_name { + my $self = shift; + my $rid = shift; + + return $rid if($rid =~ /^\d+$/); + + +} + ## @method private $ _generate_ingredients($ingreds) # Given an array of ingredients, convert them to a list of ingredients @@ -113,6 +127,11 @@ sub _generate_view { my $self = shift; my $rid = shift; + # If the rid is not numeric, assume it's a name and convert + $rid = $self -> _resolve_recipe_name($rid); + return $self -> _fatal_error("{L_VIEW_ERROR_NORECIPE}") + unless($rid); + # Try to fetch the data. my $recipe = $self -> {"system"} -> {"recipe"} -> get_recipe($rid);