Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the order of execution of Mason blocks in a component

Tags:

perl

mason

What will be the sequence of execution if these blocks are present in a Mason component?

  • %args
  • %init
  • %once
  • %shared
  • %attr
  • %flags
like image 994
Sunil Avatar asked Jul 02 '16 10:07

Sunil


People also ask

What is the execution order of blocks static blocks constructors and methods?

What is the execution order of blocks, static blocks, constructors, and methods in Java? Initialization blocks (blocks and static blocks) and constructors in a Java class are executed in following sequence: 1. Static blocks get executed at the time of class loading.

What is the Order of execution of initialization blocks in Java?

Order of execution of Initialization blocks and constructor in Java. Static initialization blocks will run whenever the class is loaded first time in JVM. Initialization blocks run in the same order in which they appear in the program. Instance Initialization blocks are executed whenever the class is initialized and before constructors are invoked.

When does a static block execute?

Static block executes only when the main method is called or every time the class gets executes . Reply ↓. Static block gets executed when class is loaded. It has nothing to do with mains method. When ever main method is called. Class gets loaded hence this behaviour.


1 Answers

There are two different kinds of blocks in that list. "Executable" blocks, which contain executable perl code, and non-executable blocks, which contain key-value pairs (not unlike perl hashes).

Executable Blocks

<%once>

This block is executed whenever the component is loaded into memory. It is executed before any other block.

<%shared>

This block is executed once per request. It is executed before the <%init> block.

<%init>

This block is executed every time the component is called. It is executed before any other code except for code in <%once> or <%shared> blocks.

Non-Executable Blocks

<%args>

This block is used to declare the arguments that a component expects. In addition, it can also be used to specify a default value if none is given when the component is called.

<%flags>

This block is used to declare special Mason flags, which are used to affect the component's behavior. Currently, there is only one flag defined, inherit.

<%attr>

This block is used to declare arbitrary key-value pairs. Unlike the <%flags> block, the contents are not used by Mason but may be used in your code.

For more information, see the Mason book, from which some of the above was copied (and modified) from.

like image 96
Avi Avatar answered Oct 20 '22 13:10

Avi