NAME

App::Framework - A framework for creating applications

SYNOPSIS

  use App::Framework ;
  
  App::Framework->new()->go() ;
  
  sub app
  {
	my ($app, $opts_href, $args_href) = @_ ;
	
	# options
	my %opts = $app->options() ;
    
	# aplication code here....  	
  }

DESCRIPTION

App::Framework is a framework for quickly developing application scripts, where the majority of the mundane script setup, documentation etc. jobs are performed by the framework (usually under direction from simple text definitions stored in the script).

This leaves the developer to concentrate on the main job of implementing the application.

To jump straight in to developing applications, please see App::Framework::GetStarted.

Capabilities

The application framework provides the following capabilities:

Options definition

Text definition of options in application, providing command line options, help pages, options checking.

Also supports variables in options definition, the variables being replaced by other option values, application field values, or environment variables.

Arguments definition

Text definition of arguments in application, providing command line arguments, help pages, arguments checking, file/directory creation, file/directory existence, file opening

Also supports variables in arguments definition, the variables being replaced by other argument values, option values, application field values, or environment variables.

Named data sections

Multiple named __DATA__ sections, the data being readily accessible by name from the application.

Variables can be used in the data definitions, the variables being replaced by command line option values, application field values, or environment variables.

Personalities

Single line selection of the base application type (i.e. command line script, Tk application, POE application etc).

Modular application framework allows for separate installation of new personalities in the installed Perl library space, or locally under an application-specific directory.

Extensions

Single line selection of one or more application extension plugins which modify the selected personality behaviour.

Modular application framework allows for separate installation of new extensions in the installed Perl library space, or locally under an application-specific directory.

Example extensions (may not be installed on your system):

Daemon

Selecting this extension converts the command line script into a daemon (see App::Framework::Extension::Daemon)

Filter

Sets up the application for file filtering, the framework doing most of the work in the background (see App::Framework::Extension::Filter).

Find

Sets up the application for file finding, the framework doing most of the work in the background

Features

Single line selection of one or more application feature plugins which provide application targetted functionality (for example Sql support, mail handling etc).

Modular application framework allows for separate installation of new features in the installed Perl library space, or locally under an application-specific directory.

Example features (may not be installed on your system):

Config

Provides the application with configuration file support. Automatically uses the configuration file for all command line option settings (see App::Framework::Feature::Config).

Sql

Provides a simplified interface to MySQL. Provides easy set up for Sql operations delete, update, select etc (see App::Framework::Feature::Sql).

Mail

Provides mail send support (including file attachment) (see App::Framework::Feature::Mail).

Application directories

The framework automatically adds the location of the script (following any links) to the Perl search path. This means that perl modules can be created in subdirectories under the application's script making the application self-contained.

The directories used for loading personalities/extensions/features also include the script install directory, meaning that new personalities/extensions/features can also be provided with a script.

Framework Components

The diagram below shows the relationship between the application framework object (Framework) and the other components: the framework derives

+--------------+
| Core         |
+--------------+
      ^
      |
      |
+--------------+
| Personality  | Script, POE etc
+--------------+
      ^
      |
      |
................
: Extension(s) :..  Filter, Daemon etc
................ :
  :...............
      ^
      |
      |
+--------------+                +--------------+
| Framework    |--------------->| Features     |-+ Args, Options, Pod etc
+--------------+                +--------------+ |
                                  +--------------+

Core and personalities

An application is built by creating an App::Framework object that is derived from the application core, and also contains 0 or more feature objects. The application core (App::Framework::Core) is not directly deriveable, you actually derive from a "personality" module that provides the base essentials for this selected type of application (for example 'Script' for a command line script).

The personality is selected in the App::Framework 'use' command as:

use App::Framework ':<personality>'

For example:

use App::Framework ':Script'

Personalities add specific methods, options, arguments to the core application.

All of the methods defined in the selected personality add to the core methods and are available to the application object ($app).

(See App::Framework::CoreModules for your currently installed personalities)

Extensions

When creating the App::Framework object, you can optionally select to derive it from one (or more) 'extensions'. An extension can modify how the application routine is called, add extra command line options, and so on. For example, the 'filter' extension sets up the application for file filtering (calling the aplication subroutine with each line of an input file so that the file contents may be filtered).

Extensions are added in the App::Framework 'use' command as:

use App::Framework '::<extension>'

For example:

use App::Framework '::Daemon ::Filter'

(See App::Framework::ExtensionModules for your currently installed extensions)

Like the personality, all of the methods defined in the selected extensions add to the core methods and are available to the application object ($app).

Features

Features provide additional application capabilities, optional modifying what the application framework does depedning on the feature. A feature may also simply be an application-specific collection of useful methods.

Unlike core/personality/extension, features are not part of the application object - they are kept in a "feature list" that the application can access to use a feature's methods. For convenience, all features provide an accessor method (access) that is aliased as an application method with the same name as the feature. This access method provides the most commonly used functionality for that feature. For example, the 'data' feature provides access to named data sections as:

my $data = $app->data('named_section') ;

Alternatively, the data feature object can be retrieved and used:

my $data_feature = $app->feature('data') ;
my $data = $data_feature->access('named_section') ;

Features are added in the App::Framework 'use' command as:

use App::Framework '+<feature>'

For example:

use App::Framework '+Args +Data +Mail +Config'

(See App::Framework::FeatureModules for your currently installed extensions)

Using This Module

To create an application you need to declare: the personality to use, any optional extensions, and which features you wish to use.

You do all this in the 'use' pragma for the module, for example:

use App::Framework ':Script ::Filter +Mail +Config' ;

By default, the 'Script' personality is assumed (and so need not be declared), and the framework ensures that all of the features it requires are always loaded (so you don't need to declare +Args, +Options, +Data, +Pod, +Run). So, the minimum is:

use App::Framework ;

Creating Application Object

There are two ways of creating an application object and running it. The normal way is:

# Create application and run it
App::Framework->new()->go() ;

As an alternative, the framework creates a subroutine in the calling namespace called go() which does the same thing:

# Create application and run it
go() ;

You can use whatever takes your fancy. Either way, the application object will end up calling the user-defined application subroutines

Application Subroutines

Once the application object has been created it can then be run by calling the 'go()' method. go() calls the application's registered functions in turn:

  • app_start()

    Called at the start of the application. You can use this for any additional set up (usually of more use to extension developers)

  • app()

    Called once all of the arguments and options have been processed

  • app_end()

    Called when app() terminates or returns (usually of more use to extension developers)

The framework looks for these 3 functions to be defined in the script file. The functions app_start and app_end are optional, but it is expected that app will be defined (otherwise nothing happens!).

Setup

DOCUMENTATION FOR THIS SECTION TO BE COMPLETED

Data

DOCUMENTATION FOR THIS SECTION TO BE COMPLETED

See App::Framework::Feature::Data for further details.

Directories

DOCUMENTATION FOR THIS SECTION TO BE COMPLETED

@INC path

App::Framework automatically pushes some extra directories at the start of the Perl include library path. This allows you to 'use' application-specific modules without having to install them globally on a system. The path of the executing Perl application is found by following any links until an actually Perl file is found. The @INC array has the following added:

* $progpath
* $progpath/lib

i.e. The directory that the Perl file resides in, and a sub-directory 'lib' will be searched for application-specific modules.

Settings

App::Framework loads some settings from App::Framework::Settings. This may be modified on a site basis as required (in a similar fashion to CPAN Config.pm).

Loaded modules

App::Framework pre-loads the user namespace with some common modules. See App::Framework::Settings for the complete list.

FIELDS

The following fields should be defined either in the call to 'new()' or as part of the application configuration in the __DATA__ section:

* name = Program name (default is name of program)
* summary = Program summary text
* synopsis = Synopsis text (default is program name and usage)
* description = Program description text
* history = Release history information
* version = Program version (default is value of 'our $VERSION')

* app_start_fn = Function called before app() function (default is application-defined 'app_start' subroutine if available)
* app_fn = Function called to execute program (default is application-defined 'app' subroutine if available)
* app_end_fn = Function called after app() function (default is application-defined 'app_end' subroutine if available)
* usage_fn = Function called to display usage information (default is application-defined 'usage' subroutine if available)

During program execution, the following values can be accessed:

* package = Name of the application package (usually main::)
* filename = Full filename path to the application (after following any links)
* progname = Name of the program (without path or extension)
* progpath = Pathname to program
* progext = Extension of program

CONSTRUCTOR

new([%args])

Create a new object.

The %args passed down to the parent objects.

The parameters are specific to App::Framework:

specification - Application definition

Instead of specifying the application in the 'use App::Framework' line, you can just specify them in this argument when creating the object. If this is specified it will overwrite any specification in the 'use' pragma.

modpod()

Create/update module pod files. Creates/updates the pod for the module lists: App::Framework::FeatureModules,App::Framework::ExtensionModules,App::Framework::CoreModules

Used during installation.

AUTHOR

Steve Price, <sdprice at cpan.org>

BUGS

Please report any bugs or feature requests to bug-app-framework at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-Framework. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc App::Framework

You can also look for information at:

COPYRIGHT & LICENSE

Copyright 2009 Steve Price, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.