Nes

 view release on metacpan or  search on metacpan

lib/Nes/Tutorial.pod  view on Meta::CPAN


=head1 NAME

Nes::Tutorial - Step by Step Nes Tutorial.

=head1 Install Nes

See: README file

=head1 Create Work Space for Tutorial

We assume you already have installed and enabled Nes for cgi-bin.

According to its distribution its web root directory could be in 
/var/www/html, /var/www/htdocs, etc.

For this tutorial we will assume that your web root directory is
/var/www, change it throughout the tutorial if needed.

Create a working directory on your web root directory with the 
name nes_tutorial

    mkdir /var/www/nes_tutorial

The next step is to set this directory to make it possible executing 
Nes templates, is done with the shell command:

    set_nes_site

Configured:

    set_nes_site --dir_cfg=/var/www/nes_tutorial

With this we have created a file .htaccess with the configuration
because Nes templates can execute in this directory.

The .nes.cfg file serve to configure Nes and also for your own
Perl script or application. There is a value that needs to be changed,
otherwise Nes release a warning:

    private_key

It is a password used to encrypt data such as cookies, so it is very 
important to give a value to private_key.

Create a file in /var/www/nes_tutorial with the name .nes.cfg, with the
following content.

/var/www/nes_tutorial/.nes.cfg:

    private_key      = ChangeIt
    nes_tutorial_var = test variable

Change 'changeit' with the password you want. And with this 
nes_tutorial is ready to work.

=head1 Create first Nes Template

Nes templates have the extension .nhtml, any file with this extension, 
in nes_tutorial directory, will be treated as a Nes template.

Create a file named 'nes_01.nhtml' in 'nes_tutorial' with following 
contents:

    <html>
      <head>
        <title>Nes Tutorial</title>
      </head>
      <body>
      <b>Hello Nes Tutorial</b>
      </body>
    </html>

To show it works:

    http://yousite/nes_tutorial/nes_01.nhtml

* Change 'yousite' with your domain or 'localhost'

'nes_01.nhtml' has no special feature, is only HTML. To include dynamic
content, must tell Nes to run a script for this template.

We therefore need a Perl script. Creates a file named 'script_02.pl' 
in 'nes_tutorial' with the following contents:

    #!/usr/bin/perl

    use Nes;
    my $nes = Nes::Singleton->new();

    $nes->out();

    1; 

It is very important that Nes scripts returns 1, or displays an error. 
Another feature is that you do not need permission of execution to run
the script, unless you want run the script and not the template.

Now we tell the template that our script is 'script_02.pl' with
the Tag '{: NES 1.0 ( 'script_02.pl' ) :}'

Therefore we create a new template with the name 'nes_02.nhtml' and
the following contents:

    {: NES 1.0 ( 'script_02.pl' ) :}
    <html>
      <head>
        <title>Nes Tutorial</title>
      </head>
      <body>
      <b>Hello Nes Tutorial</b>



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