commit a91264ac1c42bd0cb5afc1ef8471d7ab36a2bcdf
parent b09c539b32af5f3199eb975ab6a010095961893b
Author: Samir Parikh <noreply@samirparikh.com>
Date: Thu, 28 Jul 2022 14:38:36 +0000
initial commit for proverb
Diffstat:
4 files changed, 178 insertions(+), 0 deletions(-)
diff --git a/proverb/HELP.md b/proverb/HELP.md
@@ -0,0 +1,35 @@
+# Help
+
+## Running the tests
+
+There is a Perl 5 script with the extension `.t`, which will be used to test
+your solution. You can run through the tests by using the command:
+
+```bash
+`prove .`
+```
+
+## Submitting your solution
+
+You can submit your solution using the `exercism submit Proverb.pm` command.
+This command will upload your solution to the Exercism website and print the solution page's URL.
+
+It's possible to submit an incomplete solution which allows you to:
+
+- See how others have completed the exercise
+- Request help from a mentor
+
+## Need to get help?
+
+If you'd like help solving the exercise, check the following pages:
+
+- The [Perl 5 track's documentation](https://exercism.org/docs/tracks/perl5)
+- [Exercism's support channel on gitter](https://gitter.im/exercism/support)
+- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
+
+Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
+
+To get help if you're having trouble, you can use one of the following resources:
+
+- [/r/perl5](https://www.reddit.com/r/perl5) is the perl5 subreddit.
+- [StackOverflow](http://stackoverflow.com/questions/tagged/perl5) can be used to search for your problem and see if it has been answered already. You can also ask and answer questions.
+\ No newline at end of file
diff --git a/proverb/Proverb.pm b/proverb/Proverb.pm
@@ -0,0 +1,12 @@
+package Proverb;
+
+use strict;
+use warnings;
+
+sub proverb {
+ my ( $items, $qualifier ) = @_;
+
+ return undef;
+}
+
+__PACKAGE__;
diff --git a/proverb/README.md b/proverb/README.md
@@ -0,0 +1,38 @@
+# Proverb
+
+Welcome to Proverb on Exercism's Perl 5 Track.
+If you need help running the tests or submitting your code, check out `HELP.md`.
+
+## Instructions
+
+For want of a horseshoe nail, a kingdom was lost, or so the saying goes.
+
+Given a list of inputs, generate the relevant proverb. For example, given the list `["nail", "shoe", "horse", "rider", "message", "battle", "kingdom"]`, you will output the full text of this proverbial rhyme:
+
+```text
+For want of a nail the shoe was lost.
+For want of a shoe the horse was lost.
+For want of a horse the rider was lost.
+For want of a rider the message was lost.
+For want of a message the battle was lost.
+For want of a battle the kingdom was lost.
+And all for the want of a nail.
+```
+
+Note that the list of inputs may vary; your solution should be able to handle lists of arbitrary length and content. No line of the output text should be a static, unchanging string; all should vary according to the input given.
+
+## Source
+
+### Created by
+
+- @bistik
+
+### Contributed to by
+
+- @kytrinyx
+- @m-dango
+- @rfilipo
+
+### Based on
+
+Wikipedia - http://en.wikipedia.org/wiki/For_Want_of_a_Nail
+\ No newline at end of file
diff --git a/proverb/proverb.t b/proverb/proverb.t
@@ -0,0 +1,91 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+use Test2::Bundle::More;
+use JSON::PP qw(decode_json);
+use FindBin qw($Bin);
+use lib $Bin, "$Bin/local/lib/perl5";
+
+my $module = 'Proverb';
+my $sub = 'proverb';
+
+my $cases;
+{
+ local $/ = undef;
+ $cases = decode_json scalar <DATA>;
+}
+
+plan 3 + @$cases;
+
+ok -e "$Bin/$module.pm", "missing $module.pm"
+ or BAIL_OUT("You need to create a class called $module.pm");
+
+eval "use $module";
+ok !$@, "Cannot load $module.pm"
+ or BAIL_OUT("Does $module.pm compile? Does it end with 1; ?");
+
+can_ok( $module, 'proverb' )
+ or BAIL_OUT("Missing package $module; or missing sub proverb()");
+
+$sub = "${module}::proverb";
+
+foreach my $c (@$cases) {
+ no strict 'refs';
+ my $expected = join "" => @{ $c->{expected} };
+ is $sub->( $c->{param}, $c->{qualifier} || "" ), $expected, $c->{name};
+}
+
+__DATA__
+[
+ {
+ "param" : ["nail", "shoe"],
+ "expected" : ["For want of a nail the shoe was lost.\n",
+ "And all for the want of a nail."],
+ "name" : "one consequence"
+ },
+ {
+ "param" : ["nail", "shoe", "horse"],
+ "expected" : ["For want of a nail the shoe was lost.\n",
+ "For want of a shoe the horse was lost.\n",
+ "And all for the want of a nail."],
+ "name" : "two consequences"
+ },
+ {
+ "param" : ["nail", "shoe", "horse", "rider"],
+ "expected" : ["For want of a nail the shoe was lost.\n",
+ "For want of a shoe the horse was lost.\n",
+ "For want of a horse the rider was lost.\n",
+ "And all for the want of a nail."],
+ "name" : "three consequences"
+ },
+ {
+ "param" : ["key", "value"],
+ "expected" : ["For want of a key the value was lost.\n",
+ "And all for the want of a key."],
+ "name" : "one consequence, new items"
+ },
+ {
+ "param" : ["nail", "shoe", "horse", "rider", "message", "battle", "kingdom"],
+ "expected" : ["For want of a nail the shoe was lost.\n",
+ "For want of a shoe the horse was lost.\n",
+ "For want of a horse the rider was lost.\n",
+ "For want of a rider the message was lost.\n",
+ "For want of a message the battle was lost.\n",
+ "For want of a battle the kingdom was lost.\n",
+ "And all for the want of a nail."],
+ "name" : "whole proverb"
+ },
+ {
+ "param" : ["nail", "shoe", "horse", "rider", "message", "battle", "kingdom"],
+ "qualifier" : "horseshoe",
+ "expected" : ["For want of a nail the shoe was lost.\n",
+ "For want of a shoe the horse was lost.\n",
+ "For want of a horse the rider was lost.\n",
+ "For want of a rider the message was lost.\n",
+ "For want of a message the battle was lost.\n",
+ "For want of a battle the kingdom was lost.\n",
+ "And all for the want of a horseshoe nail."],
+ "name" : "whole proverb with qualifier"
+ }
+]