From eb55aa0eb51acaa56a57a44d2b543a639a9192b6 Mon Sep 17 00:00:00 2001 From: Juerd Waalboer Date: Mon, 26 Dec 2022 04:48:38 +0100 Subject: [PATCH] revbank.products: trim whitespace, document comment/whitespace rules Beginning of a line was already trimmed, courtesy of the whitespace split. The end of a line was previously not trimmed because of the limit for split. --- plugins/products | 10 +++++----- plugins/products.pod | 14 ++++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/plugins/products b/plugins/products index 139fab0..47f37e5 100644 --- a/plugins/products +++ b/plugins/products @@ -9,9 +9,10 @@ sub _read_products() { my $line = 0; for (slurp $filename) { $line++; - /^\s*#/ and next; - /\S/ or next; - chomp; + + s/^\s+|\s+$//g; # trim + next if /^#/; + next if not length; my ($ids, $p, $desc) = split " ", $_, 3; my @ids = split /,/, $ids; @@ -30,8 +31,7 @@ sub _read_products() { } my @addons; - unshift @addons, $1 while $desc =~ s/\s+ \+ (\S+) \s*$//x; - + unshift @addons, $1 while $desc =~ s/\s+ \+ (\S+)$//x; $products{$_} = { id => $ids[0], diff --git a/plugins/products.pod b/plugins/products.pod index 8715d56..53974c3 100644 --- a/plugins/products.pod +++ b/plugins/products.pod @@ -10,10 +10,20 @@ products - RevBank plugin for selling products =head1 DESCRIPTION -This plugin turns products from a product list into RevBank commands. +This plugin turns products from a product list into RevBank commands, +that add the respective products as Entries to the current Cart. + +=head1 CONFIGURATION The configuration for this plugin lives in a text file called -C, which has whitespace-separated columns: +C. + +Whitespace at the beginning or end of a line are ignored. Blank lines are +ignored. Comments are lines that start with C<#> and are also ignored. Note +that a whole line is either a comment or a data line; trailing comments are +not supported and C<#> is a valid character in a product description. + +Data lines have whitespace-separated columns: =head2 Product ids