Chapter 1.1: Helper

There is a Genelet::Helper package in Genelet. A shell command help.pl is distributed together. For novice developer, you are recommended to run this program. It generates a layout of basic Perl classes, templates, config.json and CGI script.

To use it, go to the directory containing help.pl, and run:

>$ ./help.pl [options] table1 table2 ...
 --dir project root, default '~/HOME/tutoperl'
 --dbtype database type 'sqlite', 'pg' or 'mysql', default 'mysql'
 --dbname database name, mandatory
 --dbuser database username, default ''
 --dbpass database password, default ''
 --project project name, default 'myproject'
 --script script name, default 'myscript'
 --force if to override existing files, default false
 --angular if to include Angular 1.3 files, default false

 

If it is successful, you will find the following tree structure in geneletperl:

geneletperl
          > bin
              - myscript
          > conf
              - config.json
          > lib
              > Myproject
                        - Model.pm
                        - Filter.pm
                        > Table1
                               - Model.pm
                               - Filter.pm
                               - component.json
                        > Table2
                               - Model.pm
                               - Filter.pm
                               - component.json
          > views
                > admin
                      > table1
                             - topics.html
                             - edit.html
                             - startnew.html
                             - insert.html
                             - update.html
                             - delete.html
                      > table1
                             - topics.html
                             - edit.html
                             - startnew.html
                             - insert.html
                             - update.html
                             - delete.html
                > public
                       > table1
                              - startnew.html
          > www

The layout shows a basic development environment in Genelet. If you are an experienced developer, you may manually build up the layout.

 

bin

A directory for executable programs. Here is the CGI program myscript.

conf

For configurations. Here is config.json. You may put your database schema and other initial settings here.

lib

For Perl packages and being under PERL5LIB. Project’s classes Model.pm and Filter.pm should be in the same directory as all component names, and each component has its own Model.pm and Filter.pm, and component.json for the configuration of the classes. In the inheritance hierarchy, project inherits from Genelet, and component inherits from project.

views

For HTML templates.  They are placed in the tree structure: role/component/action.html.

www

Optionally for the Angular 1.3 one-page web site. See here.

If you are an experienced developer, you can pass help.pl and go directly to manually create all the above files by yourself.

Perl Development Manual

Contents:

  1. Introduction
    1. Helper
    2. Accessor
    3. CGI Script
    4. Database Methods
  2. Model
    1. Genelet::Model
    2. Add Class Method
    3. Project
    4. Component
    5. Pagination
    6. JOIN Tables
    7. Triggers
  3. Filter
    1. Accessors and ACL
    2. File Uploading
    3. RLS
    4. Get Action
    5. Preset
    6. Before
    7. After
    8. Sending Email

 

Download

The Perl Framework can be downloaded from GitHub:
git clone git@github.com:genelet/perl.git YOUR_DIRECTORY

 

Best Practice

Here is the list of few guidelines you should follow in design of classes.

  • Class attributes are always expressed in upper-cases.
  • In class methods, always return nothing from a successful run, otherwise, return an error code or error string.
  • Use setup_accessors to build Getter, Setter for attributes and to initialize them.

 

For Experienced Developers

The Perl version of Genelet is nothing more than a collection of well-thought CGI/FCGI packages to develop large-scale web project in a convenience, fast and organized way. While you are still be able to do everything in your own style, the packages are aimed nevertheless to be the most efficient and elegant solutions.

Genelet will force you, and guarantee you, to have a clean set-up and development foundation that would grow linearly, not exponentially with the size of project. Instead of digging into legacy code and debugging, you could gain more time in designing business logic, data model, or planning future growth.

Genelet has little dependence on 3rd party packages. The list is very short. They are: JSON (for JSON), XML::LibXML (for XML), DBI (for database), LWP::UserAgent (for OAuth etc.), URI and URI::Escape (for URL manipulation), Digest::HMAC_SHA1 and MIME::Base64 (for security), Net::SMTP (for email), Template (for HTML5 templates), and Test::More (for unit testing). The minimal Perl version it works with is 8.10.

Future more, Genelet is a protocol. You can easily switch from Perl to GO or Java, or vice versa, with only a minimal effort. In particular, your database and public APIs will be kept the same.

 

For Novice Users

Genelet is in Object-Oriented Perl. It follows strict MVC pattern and provides full RESTful API access. Popular services like OAuth login, SMS and mobile push notifications etc. are built-in and ready to use. It has also a debugging tool to find problems. As an add-on, there is a bridge Javascript file for you to develop one-page website using Angular 1.3 web framework.

While Genelet is as powerful as, if not more powerful than, other frameworks, it is definitely a lot easier to learn and takes much shorter development circle to finish web project.

The only major idea that has not been incorporated into Genelet is ORM, Objected Relational Mapping. Alternatively, Genelet has its own packages to operate on database, include a complete set of CRUD/REST subroutines to run raw SQLs and stored procedures. However, you can always bring in your favored ORM. Genelet works with every CPAN module in the same way as a normal Perl program.

 

Virtual Hosting

For those working under a virtual hosting environment, Genelet is always able to run in the CGI mode. It would be very likely to run in the Fast CGI mode too, as far as the virtual hosting provider runs PHP under Apache’s mod_fcgid.  You can develop in CGI, and switch to Fast CGI anytime to gain the PHP speed.