Just read Poet :: Import .
A simple example:
# generate app My poet new my cd my
add class My::Import , for example
vi lib/My/Import.pm
and add to it
package My::Import; use Poet::Moose; extends 'Poet::Import'; use Types::Path::Tiny qw(Path);
eg. Poet::Import already imports the variables $conf and $env (as well as the utility tag :web ). Thus, you simply extend Poet::Import by adding another “attribute” (your “variable”) to it.
In the example above
- added
mytemp attribute - and want to call a global variable like
$mytemp .
Now you can use it, for example, in your components. Change your comps/index.mc .
Add to top
<%class> use Poet qw($mytemp);
and add the following:
<h1>My files in the /tmp</h1> <pre> % for my $file ($mytemp->children) { <% $file %> % } </pre>
$mytemp $mytemp imported from My/Import.pm . (this is read-only, by definition - (is => 'ro',... ).
Everything is in Poet/Mason Moose :), so (of course) you can import the rw variable with any isa ... etc.
Just remember that this is a true global and constant variable. For instance. its contents are stored between requests. In most cases, you do not want to use such variables, only in a few special cases, for example, you want to initialize some $dbh database descriptor (which should be accessible by running applications), etc.
Secondly, the $m->notes method is also used here, but do not overwork it. From docs :
The notes () method provides a place to store application data between components - essentially a hash that remains throughout the request.
Consider storing this type of data in the read-write attribute of the page component.
Basically, it’s enough to use simple component attributes, for example. see, for example, in a generated application, the default use of $.title (for example, $ self-> title).
Or you can just pass variables to the components as arguments,
<& somecomp.mc, arg1 => 'some', arg2 => 'other' &>
etc.
Again, each component :
- just a camel
- with horns
- using some masonry tools
- in a poetic environment
- at the top of the psgi hill
:)