Use Object Oriented Perl to build Web & Email Applications

The books and tutorials available to help you take your procedural style of Perl programming into the world of Object Oriented Perl vary a lot, which is perhaps another reflection of the great flexibility Perl allows you. The learning resources and design patterns out there range from a very simple use of classes, objects and methods all the way up to the very advanced and rather complex methodologies you will find in Damian Conway's authoritative book on the subject: Object Oriented Perl. Coming soon to this site are tutorial videos on OO Perl beginning on a level which is immediately useful in practice, so to lead into that I will begin creating and documenting some basic OO Perl classes and modules along with code which uses them, and since Email and Web systems for the Enterprise are our focus on this site, we will start right out building them.

oop moduleObject Oriented Perl Module to Send an Email


To launch 2010, I have more Object Oriented Perl Modules coming up as well as my long-planned push into a new AJAX/Javascript front-end for this website. After a lot of research and testing I have come to a final decision on a framework to take deepvirtual.com into the world of dynamic user interfaces known as Web 2.0. I have selected JQuery for its power and ease of use. At a later stage, if I want similar power and elegance but also need a robust Object Oriented design in my Javascript framework, I may also include or migrate to MooTools. To enhance the PHP backend with Model-View-Controller capabilities and other powerful application-server capabilities, I have selected CodeIgniter as my PHP framework. Again, a balance between power, quality, ease of use and light weight were the criteria I went by in my comparisons and trial implementations to come to my final selection. JQuery and CodeIgniter together with elegant design and coding is the kind of mix of technologies which enhance applications like Facebook, Flickr, Google Maps and your other favorite sites which have the feel and power of a desktop application, except it's your web browser! The enhancement of this site begins now, so you can watch the evolution of deepvirtual.com take shape as we kick off 2010!


Using Perl to Generate Excel Spreadsheets

Excel Spreadsheets, also known as XLS files, through the use of Microsoft Excel and now also OpenOffice, are frequently the preferred and portable way of working with tabular data, especially for business folks who want to see charts and want to be able to take the document and data with them on laptops and work with that data. This preference and the prevalence of Excel skills by business users and executives leads to the need to automate the output and manipulation of data from potentially large databases, via Perl, into the XLS file format. There are many options and issues to address when you want to pull data from an Oracle or MySQL database for example, possibly manipulate that data or do some intermediate processing, and then write that data to Excel spreadsheets with the automatic generation of charts and graphs and other powerful features. Here weexplore the various CPAN modules and techniques with source code included.
Outputting Data from DBs into Tables, Charts and Graphs in Excel Spreadsheets using Perl


Essential Infrastructure CPAN Modules

DBI + DBD::mysql is the standard method for working with a MySQL Database in Perl. The DBD::mysql module is one of the more complex modules to build because of its requirement for external mysql client libraries as well as other requirements to be able to complete the full set of tests done at build time. As a recently-introduced alternative, the pure Perl Net::MySQL can be used. The Perl DBI + DBD::mysql combination probably offers more speed for some operations on large result sets or large inserts and is by far the most common data access layer for MySQL found in legacy Perl applications.
DBD::mysql 4.013 on CPAN

XML Perl Modules. The link below provides an extensive list of Perl modules for the manipulation of XML; parsing, reading, writing, encoding, converting and more. There is a strong movement in Enterprise Application Development to develop applications around XML for data interchange and storage. There is also a strong movement to migrate existing applications to XML for interchange and storage as new apps and legacy apps are plugged together. As another important strong standard, part of a good foundation for the enterprise, adoption of standardized XML use is best done early and thoroughly. Only in the context of an extreme performance need which has exhausted all other performance-enhancement options, should XML be abandoned as a data transfer and storage medium, either between applications or within complex enterprise applications.
Perl XML Module List

Net::MySQL is a pure Perl alternative to using DBI + DBD::mysql which can be used in environments in which, for one of many possible reasons, the prerequisite mysql client libraries are not available or DBD::mysql cannot be compiled. It is rare to have an environment in which it is not eventually possible to run a mysql client, but there are sometimes procedural or security issues that might be in the way of using DBI + DBD::mysql right when you want to. Net::MySQL, being pure perl, will work with only a basic Perl installation since its only dependency is the core module IO::Socket for making the TCP connection to your MySQL Server. Net::MySQL is intended as an easy replacement for DBI + DBD::mysql so the syntax is very similar.
Net::MySQL 0.09 on CPAN

Web Standards, Protocols and Technologies

Web Development that seeks to maximize performance and user experience across all platforms and devices while minimizing development and maintenance overhead will be striving for near 100% compliance with XHTML 1.0 Transitional and CSS2.1. Integral to your Web Development, AJAX, XML, SOAP and related technologies also need to maximize a modern standards-compliance for an optimal development recipe, and we will detail all of the technologies and versions of languages and protocols later. As the foundation for your web and rich content you publish and operate, for desktop as well as mobile platforms and as the presentation framework for your web and mobile applications, you will want to have a quality baseline of standards-compliant XHTML 1.0 Transitional and CSS2.1, as of this Fall of 2009. A fact of life is also that even in the very best of scenarios and with efforts to not over-complicate your web design, integrated content and Web 2.0+ functionality, you will still encounter frustrating misbehaviour and bugs when you test with the handful of most prevalent browser brands and versions. Sometimes with a few small trade-offs made in both areas of layout and design as well as complexity of javascript/AJAX functionality, it is quite possible to achieve both high-cross-browser, operating system and cross-device performance with a modern, fully or near-fully standards-compliant basis for your Web space.
XHTML 1.0 The Extensible HyperText Markup Language (Second Edition)
Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification

CPAN Modules for Email

Email::Valid validates many aspects of the actual deliverability of an email address or a domain name by performing a number of network tests such as checking DNS for an A or MX record and actually connecting to the remote email server, if one exists. Prior to using the network checks of Email::Valid, you may have already checked that an email address is composed with a valid syntax, using a module such as Email::Address or Regexp::Common::Email::Address. Preferably the syntax check was done previously or at data acquisition time, but the network checks done by Email::Valid are very important prior to bulk attempted delivery, unless you want to have your outbound email servers working away on invalid domains or nonexistent email servers, ultimately getting blocked and/or blacklisted by the remote ISPs. There is still a lot more involved in cleaning lists and optimising bulk delivery, but when it comes to the essential and ongoing task of cleaning a customer database or mailing list to reduce the challenges of email direct marketing, Email::Valid is an important tool.
Email::Valid 0.182 on CPAN

Mail::Box::Manager of the extensive Mail::Box suite allows you to access and manipulate folders of email messages as a user's email program might. It can be thought of as a backend to an MUA or 'Mail User Agent'. A user's email program is an MUA. Mail::Box::Manager can work against a number of different mail store or message store formats, from formats like maildir which store each email in a single file, to formats like mbox, which store multiple emails in a single text file, each mbox file containing multiple emails can correspond to one folder of emails, sometimes also referred to as being a specific 'mail box' of emails, like Incoming or Inbox, thus one account can have multiple mbox files, Sent and Drafts being some other common ones. Similar to Sendmail and others, the Postfix Email Server (aka MTA or Mail Transfer Agent) typically spools incoming email onto the end of plain text files in the mbox format. Mail::Box::Manager can be used to open mbox or maildir format files and can read, move, delete and create email messages in those folders/mail boxes, among other things. If you are writing software in Perl to operate against email stored in the mbox or maildir formats or other formats, then Mail::Box and its Mail::Box::Manager and the numerous supporting modules within the Mail::Box collection will give you a powerful, albeit somewhat complex and heavyweight array of tools for performing almost any function you might require.
Mail::Box 2.091 on CPAN

Net::SMTP is part of the libnet set of modules which provides facilities for a number of network protocols. This is a client interface to ESMTP or Extended Simple Mail Transfer Protocol, in addition to the original basic SMTP. RFC 2821 which defines SMTP and ESMTP is detailed below. Net::SMTP is a simple object oriented module which connects to a remote MTA, meaning Mail Transfer Agent or Mail Server and executes the appropriate series of commands in SMTP to inject a single email for delivery by the MTA. Some of the other protocols covered by libnet are handled by the appropriately named Net::POP3, Net::Time and Net::FTP modules. Libnet maintains its own locally-saved configuration handled by the Net::Config module, via which default settings can be specified at install time. Before you begin the installation of libnet, you should have a list of hostnames, usernames and passwords etc. ready for the various services like SMTP, FTP and POP3 which you would like to fully test libnet against at installation time.
libnet 1.22 on CPAN

Mail::Message is a subset of modules, also within the extensive Mail::Box suite, containing a variety of modules for manipulating, parsing, converting and performing other functions upon the various parts of an email message. The Mail::Box suite also contains a few other, less-frequently used email server/transport-related modules. By far the most practically useful modules within Mail::Box are Mail::Box::Manager and the set of Mail::Message modules.
Mail::Box 2.091 on CPAN

Mail::SpamAssassin is the object-oriented module implementation of the SpamAssassin email filtering application. SpamAssassin can also be used from a constantly-running daemon/service as well as a command line tool. CPAN's Mail::SpamAssassin is ideal for integrating this powerful filtering into your Perl applications. An organization which sends direct marketing email in bulk out onto the Internet at large, does well to run its emails through SpamAssassin prior to initiating a campaign because that email is going to encounter a lot of instances of SpamAssassin on its way to final delivery. It is very wise to check how your proposed bulk email is going to perform through all major filtering products. So using Perl and Mail::SpamAssassin to integrate SpamAssassin results reporting into the pre-publishing QA cycle is an obvious use case. Folks who administer corporate incoming email servers might also find powerful custom implementation options using this Perl module. With respect to Spam filtering, SpamAssassin is right up there with the leading commercial products like Symantec's BrightMail and IronPort's secure email appliances. A large organization might very well use a combination of multiple solutions, both for protecting incoming email as well as pre-screening bulk outbound email to best validate its real-world deliverability.
Mail::SpamAssassin 2.43 on CPAN
The Apache SpamAssassin Project

Email Standards, Protocols and Technologies

RFC 2822, The Internet Message Format (Definition of an Email) is the authoritative specification of Electronic Mail with respect to the text message itself, most importantly, email headers and addresses. RFC 2822 defines only the simplest level of basic structure of the body of the email message and does not get into rich content or attachments. Relevant to other RFCs covering the functionality of transport or sending and receiving of email, RFC 2822 defines the fields in the header portion and their requirements. It details formats for origination and destination address and date fields, resent fields, trace, informational and optional fields and other aspects of email headers. Officially titled as the Standard for the Format of ARPA Internet Text Messages, RFC 2822 also defines the format of a valid email address. We turn to other RFCs to cover the transport or sending and receiving of email by various software 'agents' or services or other integral facilities like the encoding of content, multi-part and rich content and attachments.
RFC 2822 as of April 2001, from IETF

RFC 2821, Simple Mail Transfer Protocol (SMTP, The Transport of Email) is the authoritative specification of Electronic Mail Internet Transport. This paper defines how email is sent, received, queued and relayed from email server to email server, among other things. Relaying, retrying of delayed deliveries, the SMTP protocol itself, timeouts, SMTP error codes, DNS MX record functionality, CC and BCC behaviours and many other related areas are specified in detail.
RFC 2821 as of April 2001, from IETF

Essential General Purpose CPAN Modules

Config::Std provides a good file-based configuration system for your perl programs which can accept name to single-value as well as name to multi-value configuration sets which can also have multiple named sections allowing for a 3-level-deep hash-in-a-hash-style configuration space. You can load as well as save configuration sets. Commenting within configuration files is provided for. The file format is a slight extension of the Windows INI format.
Config::Std 0.0.5 on CPAN

Date::Parse is an important module for handling the very common and often challenging task of parsing and converting dates and times which come in a wide variety of formats. Typical date and time formats you will want to parse come from HTTP logs, email headers, the unix date program and other sources and can vary in a number of ways, such as being in 12 vs 24 hour time, including or excluding a time zone to name just a few sources of variation. To perform date/time calculations you will typically want to use a module such as Date::Parse to convert your source data into Epoch Seconds, prior to your calculations and possible conversion back out to a different date/time format. For that initial conversion to Epoch Seconds, Date::Parse will meet most of your needs and when it can't handle a format, usually only a small adjustment to the format will give it something it can reliably convert.
Date::Parse 1.19 on CPAN

CPAN's Storable module provides persistence on disk for any kind of Perl data structure. By simply specifying a reference to any type of perl variable or data structure and a file path, you can write an image of that structure to disk and retrieve it at a later time to completely restore it back into memory. Storable provides the Perl programmer with a very powerful and easy to use mechanism for implementing caching functionality for such things as a web content proxy, intermediate data cache or a cache of objects representing the state of an application, thus allowing you to save and resume an application which might have a complex space of operating state. With a module like storable, you don't need to reinitialise every aspect of your application as this tool will allow you to have a warm start up, or provide you with a facility for more complete crash recovery or a 'resume' capability. In general, writing and reading data structures to and from disk is known as serialization and Storable is your number one way to accomplish this in Perl.
Storable 2.21 on CPAN

Resources for Developers


Portfolio of Web Designs, User Interfaces and Graphics