NAME

Language::AttributeGrammar::Thunk - Delayed code logic

DESCRIPTION

This is a four stage thunk.

    stage 1: code unset
    stage 2: code set, unevaluated
    stage 3: code being evaluated
    stage 4: code evaluated and return value stored
  • new($class, ?$code, ?$attr, ?$at)

    Creates a new thunk object. If $code, $attr, and $at are specified, initializes the object via set.

  • $thunk->set($code, $attr, $at)

    Set the code for a thunk. $attr is the name of the attribute that this code is evaluating (for example "Cons:length") and $at is a description of the location at which the thunk was defined (for example "grammar.pl line 42"). Both of the latter two are only used for diagnostic purposes. This method is only valid when the thunk is in stage 1 (and it moves it to stage 2).

  • $thunk->get($attr, $at)

    valuate a thunk. $attr is the name of the attribute that is being fetched, and $at is a description of the location at which it is being fetched. In stage 1 it fails because there is no code to evaluate, and in stage 3 it fails because this implies that an infinite loop would occur. After successful execution of this method, the thunk is in stage 4.

SEE ALSO

Language::AttributeGrammar, Data::Lazy