perl

Standard Library documentation

Evaluate Perl code from ZuzuScript.

Module

Name
perl
Area
Standard Library
Source
modules/perl.zzm

NAME

perl - Evaluate Perl code from ZuzuScript.

SYNOPSIS

  from perl import Perl, PerlResult;

  let r := Perl.eval("[ 7, 8, 9 ]");
  assert( r instanceof PerlResult );

  let j := r.toJSON();

  let r2 := r.eval(" $_->[1] ");
  assert( r2 instanceof PerlResult );

  let n;
  n := r2.value() if r2.isSafe();

IMPLEMENTATION SUPPORT

This module is supported by zuzu.pl. It is not supported by zuzu-rust or zuzu-js.

DESCRIPTION

This builtin module bridges to the host Perl interpreter.

Perl.version() returns the current Perl version string.

Perl.eval(String code) evaluates Perl in scalar context and returns PerlResult.

PerlResult wraps the underlying Perl value. Use isSafe() to check whether value() can convert it into a native Zuzu value.

toJSON() attempts to encode the wrapped value as JSON text.

eval(String code) evaluates more Perl with the wrapped value in $_, again returning PerlResult.

EXPORTS

Classes

  • Perl

    Runtime-supported Perl bridge class.

    • Perl.version()

      Parameters: none. Returns: String. Returns the host Perl interpreter version.

    • Perl.eval(String code)

      Parameters: code is Perl source text. Returns: PerlResult. Evaluates code in scalar context in the host Perl interpreter.

  • PerlResult

    Wrapper for a Perl value returned by Perl.eval() or PerlResult.eval().

    • result.eval(String code)

      Parameters: code is Perl source text. Returns: PerlResult. Evaluates code with the wrapped Perl value available in $_.

    • result.isSafe()

      Parameters: none. Returns: Boolean. Returns true when value() can convert the wrapped Perl value into a native ZuzuScript value.

    • result.value()

      Parameters: none. Returns: value. Converts and returns the wrapped Perl value when isSafe() is true.

    • result.toJSON()

      Parameters: none. Returns: String. Serializes the wrapped Perl value as JSON text.

COPYRIGHT AND LICENCE

perl is copyright Toby Inkster.

It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.