6

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

  • %args
  • %init
  • %once
  • %shared
  • %attr
  • %flags
Borodin
  • 126,100
  • 9
  • 70
  • 144
Sunil
  • 856
  • 12
  • 24
  • 1
    Feel free to make a test template, run it and see compiled in the code cache. I've done it when made plugin for it. But not remember now :) Here is hierarchy: https://github.com/Camelcade/Perl5-IDEA/issues/905 – Alexandr Evstigneev Jul 02 '16 at 16:22
  • Thanks for sharing the link. Just wanted to know about %attr. Where does %attr fit in that hierarchy? – Sunil Jul 02 '16 at 16:36
  • Thanks let me figure out with the method you have mentioned. – Sunil Jul 02 '16 at 16:54
  • @AlexandrEvstigneev: If you have a reference that helps then you should post it and explain it. I'm not at all sure that the page that you have linked is supposed to represent a hierarchy – Borodin Jul 02 '16 at 18:50
  • 1
    @Borodin I've offered a method how to see the sequence. I've provided link to the data i've done when solved the similar problem. In other words: i've shared my experience in amount and manner I can afford now. And It's better than do nothing. – Alexandr Evstigneev Jul 02 '16 at 19:15
  • @AlexandrEvstigneev: Throwing up a link that you think may help or may be completely wrong isn't better than doing nothing. And you may not realise it, but *"Feel free to make a test template"* implies that you have the authority to prevent thew OP from doing just that, which you don't – Borodin Jul 02 '16 at 21:32
  • @Borodin I respectefully disagree about doing someting and doing nothing. And yes, my English is bad, sorry :( – Alexandr Evstigneev Jul 03 '16 at 05:53
  • @Borodin and according to "how to answer" manual: Any answer that gets the asker going in the right direction is helpful – Alexandr Evstigneev Jul 03 '16 at 06:00

1 Answers1

13

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.

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
Avi
  • 1,231
  • 10
  • 23