CODE
Runs a block of Perl on the Clarive server. Deprecated: the palette lists it as
(DEPRECATED) CODE (Perl) with the name struck through, and
Server CODE covers the same ground with a choice of language and a
working Return Key. Existing rules still work, so there is no hurry, but write new blocks in the
newer op and read the scoping difference below before you move an old one.
Fields¶
Code¶
The Perl block. The editor highlights Perl and has no language selector, since Perl is the only
option this op has. The text is compiled into the rule exactly as typed. ${...} placeholders are
not expanded, so read stash values through the $stash hash reference that is in scope, the same way
as in any other rule code.
Leave it empty and the op still registers a step in the job log and then does nothing.
How it differs from Server CODE¶
Return Key on the op's Options tab does nothing here. Whatever the block evaluates to is dropped on
the floor. It is a field you can fill in, save and never see any effect from, which makes it one of
the quieter traps in the palette. To pass a value on, write it into the stash yourself.
The block is also spliced straight into the rule rather than wrapped in a scope of its own. A my
variable declared here is still visible to the ops below it at the same nesting level.
Server CODE always wraps its Perl in a scope, whether or not you set
a Return Key, so the same declaration there is gone by the next op. Rules that lean on the leak
break on a naive migration; move those values into the stash first, then switch the op.
Failure and flow¶
A syntax error in the block stops the whole rule before any of it runs, including the ops above this
one. A runtime error stops the rule at this point. Set Error Handling on the Options tab, or wrap
the op in TRY statement and
CATCH statement, to survive either.
The whole rule compiles into a single routine, so a return statement inside the block ends the
entire rule on the spot. The remaining ops are skipped and nothing in the log explains the gap.
Finish with a plain statement instead.
The op writes one entry to the job log, the node name from the rule tree, and nothing else. That
name has its ${...} placeholders expanded before it is logged. Use
LOG Message for anything else the operator needs to read.
Combining with other ops¶
The same pairings as Server CODE: prepare a value here, branch on it with IF var condition THEN, walk a list with FOREACH file/item, stop the rule with FAIL. For a single expression, SET EXPR is shorter and keeps the variable name visible in the tree.
Examples¶
Take a timestamp in one op and use it further down the rule. The lexical variable survives because the block is not scoped, which is the one thing this op does that the newer one does not.
Code:
my $started = time;
...later in the same rule, another CODE op:
Code:
my $elapsed = time - $started;
Written for Server CODE the same pair has to go through the stash.
The first block returns the timestamp under a Return Key, and the second reads started_at back
out of the stash rather than relying on a lexical.
Programming language: Perl
Return Key: started_at
time;