The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.


Parse::Tinymush - A simple tinymush parser


  use Parse::Tinymush;
  my $functions = {
    cat => [sub { "@_" }, -1],
    add => [sub { $_[0] + $_[1] }, 2],
  my $parser = Parse::Tinymush->new(functions => $functions);
  print $parser->parse("add(1,2)");


The Parse::Tinymush module is an implemenation of the tinymush parser written in perl. This implementation comes with no built-in %-variables or functions, but they can be easily added by passing arguments to the constructor.


new is the constructor. It sets up various instance variables. The constructor takes a number of optional arguments:


This must be a reference to a hash with the form:

  { function_name => [code_ref, argument_count, flags] }

function_name must be lowercase for the parser to work correctly. argument_count can be one of the following:

* -1, which means any number of arguments

* A number, which means that exact number of arguments

* An array ref, whose first entry is the minimum number of arguments and second entry is the maximum number of arguments.

The flags field is optional. The possible values for it are:

* FNC_NO_FLAGS (0) - Same as not having any flags

* FNC_PASS_NAME (1) - Pass the function name as the first argument to the function. This allows the same code to have different function names. This is useful if you wish two functions to have similar features, but do not want to repeat code.


  my $functions = {
    "add" => [ \&fnc_add, 2, ],
    "cat" => [ \&fnc_cat, -1, FNC_NO_FLAGS ],
    "lcon" => [ \&fnc_lcon, [1, 2], FNC_PASS_NAME ],

The variables hash is used to handle evaluation of the %-variables. It must be a reference to a hash with the form:

  { var_name => var_eval }

var_name is case-sensitive. For both "C" and "c" to mean the same thing, they must both be in the table. var_eval can be one of the following:

* A simple scalar

* An array ref, in which case the current character is used as the index

* A hash ref, in which case the current character is used as the key

* A code ref, in which case the code is called, passing it the current character and the Parse::Tinymush object as $_[0] and $_[1]

* An object with an eval method, in which case the method is called and passed the current character and the Parse::Tinymush object


  my @array = ( 0 .. 9 );
  my %hash = ( y => "z" );

  my $variables = {
    "!" => $$,
    "0" => \@array,
    "y" => \%hash,
    "l" => sub { getcwd; ),
    "o" => HTML::Parser->new(),

options is a hash reference of various parser options. Currently, the only supported option is space_compression.

* space_compression - default: on - When on, multiple spaces will be compressed into one space.


my $parser = Parse::Tinymush->new(options => {space_compression => 0});


parse parses the given string, returning a string as the result.


my $output = $parser->parse("cat(1,2,3,4,5)");

# $output = 12345




The tinymush project: <>


Eric Kidder, <>


Copyright (C) 2003 by Eric Kidder

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.1 or, at your option, any later version of Perl 5 you may have available.

1 POD Error

The following errors were encountered while parsing the POD:

Around line 476:

=back doesn't take any parameters, but you said =back 4