Nes

 view release on metacpan or  search on metacpan

share/examples/nesblog/en/items/Singleton.nhtml  view on Meta::CPAN

<p>In the parameter we pass a copy of hash (%$hash) with the data we want
to replace in the template.</p>
<pre>
    my $nes_tags = {};
    $nes_tags-&gt;{'hello'} = 'Hello World!';
    $nes-&gt;out(%$nes_tag);

    ./.

    my %nes_tags;
    $nes_tags{'hello'} = 'Hello World!';
    $nes-&gt;out(%nes_tag);
    
</pre>
<p>The method 'out' does not exit script or immediately print values, 
your script can continue after call to out, but for clarity it is 
recommended to include at the end of script.</p>
<p>This will work:</p>
<pre>
    ...
    $nes-&gt;out(%$nes_tag);
    &amp;foo($bar);
    ...

</pre>
<p>For clarity use this:</p>
<pre>
    ...
    &amp;foo($bar);
    $nes-&gt;out(%$nes_tag);
    ...
    
</pre>
<p>
</p>
<h3><a name="add">add</a></h3>
<p>Added Tags without sending out. If you template:</p>
<pre>
    &#123;: NES 1.0 ('myscript1.pl','myscript2.pl') :&#125;
    
</pre>
<p>If myscript1 and myscript2 defined Tags, mysqcript1 should have:</p>
<pre>
    $nes-&gt;add(%tags);
    
</pre>
<p>And myscript2:</p>
<pre>
    $nes-&gt;out(%tags);
    
</pre>
<p>If you call to out method in myscript1, the tags of myscript2 never be replaced. 
If you not call to out method in last script, the Tags never be replaced.</p>
<p>The routine use of the add method is in creating plugin.</p>
<p>
</p>
<hr />
<h2><a name="_nes_cfg">.nes.cfg</a></h2>
<p>You .nes.cfg contains:</p>
<pre>
    private_key   = pass3
    myscript_var1 = 50
    
</pre>
<p>Then you can access:</p>
<pre>
    use Nes;
    my $nes    = Nes::Singleton-&gt;new('template.nhtml');
    my $config = $nes-&gt;{'CFG'};

    my $var  = $nes-&gt;{'myscript_var1'};
    my $pkey = $nes-&gt;{'private_key'};

    # Global configuration
    my $pdir = $nes-&gt;{'plugin_top_dir'};
    
</pre>
<hr />
<h2><a name="session">Session</a></h2>
<pre>
    my $nes     = Nes::Singleton-&gt;new();
    my $session = $nes-&gt;{'session'};

    # Create session:
    $session-&gt;create($user, $expire);

    # Get session:
    $user = $session-&gt;{'user'};

    # Delete session:
    $session-&gt;del;
    
</pre>
<p>
</p>
<hr />
<h2><a name="query">Query</a></h2>
<pre>
    use Nes;
    my $nes   = Nes::Singleton-&gt;new('template.nhtml');
    my $query = $nes-&gt;{'query'};
    my $q     = $query-&gt;{'q'};
    
</pre>
<p>Nes::Singleton-&gt;{'query'}-&gt;{'q'} is equivalent to do:</p>
<pre>
    use CGI;
    my $q = CGI-&gt;new;
    
</pre>
<p>In addition to GET or POST with Nes::Singleton-&gt;{'query'} we pick 
parameters of Nes Objects in the following format:</p>
<pre>
    objectname_param_number
    
</pre>
<p>For our example the name of the object is lucky.nhtml, the extension 
is ignored, then the first parameter:</p>
<pre>
    Nes::Singleton-&gt;{'query'}-&gt;{'q'}{'lucky_param_1'}
    
</pre>
<p>The object name is:</p>
<pre>
    my $obj = Nes::Singleton-&gt;{'query'}-&gt;{'q'}{'obj_param_0'};
    my $par = Nes::Singleton-&gt;{'query'}-&gt;{'q'}{$obj.'_param_1'};
    
</pre>
<p>The following variables are available in .nes.cfg for POST control:</p>
<pre>

    max_post   = 512  # Max kB. maximum size of POST.



( run in 0.702 second using v1.01-cache-2.11-cpan-39bf76dae61 )