Perl (Practical Extraction and Report Language) is the language we use to implement the in-house components of the FCM system. This document contains some basic guidelines that are followed by the Perl code in FCM.
There are many Perl style guides available online. Some are listed below:
The Perl Best Practices book is the most comprehensive of all. In FCM, we have begun to write new modules to follow its advice. However, we recognise that it may not be possible to strictly follow every detail, as Perl is a language designed to do things in different ways. The most important point is that the style within a source file should be consistent and easy to follow, so the next person who reads it will not have to struggle with it. It is also worth nothing that many older modules in the FCM source tree are still written to an old style which was derived before we found out about this book.
A typical Perl executable in FCM looks like:
#!/usr/bin/env perl #------------------------------------------------------------------------------- # (C) Crown copyright Met Office. All rights reserved. # For further details please refer to the file COPYRIGHT.txt # which you should have received as part of this distribution. #------------------------------------------------------------------------------- use strict; use warnings; use FindBin; use lib "$FindBin::Bin/../lib"; if (!caller()) { main(@ARGV); } sub main { local(@ARGV) = @_; # ... } 1; __END__ =head1 NAME fcm-example =head1 SYNOPSIS fcm-example [OPTIONS] [ARGS] =head1 OPTIONS ... =head1 ARGUMENTS ... =head1 DESCRIPTION An example boiler plate for an FCM Perl executable. =head1 DIAGNOSTICS ... =head1 CONFIGURATION AND ENVIRONMENT ... =head1 COPYRIGHT (C) Crown copyright Met Office. All rights reserved. =cut
A typical Perl module in FCM looks like:
#------------------------------------------------------------------------------- # (C) Crown copyright Met Office. All rights reserved. # For further details please refer to the file COPYRIGHT.txt # which you should have received as part of this distribution. #------------------------------------------------------------------------------- use strict; use warnings; #------------------------------------------------------------------------------- package FCM::Example; # For example... sub example { my ($message) = @_; sprintf('E.g. %s.', $message); } #------------------------------------------------------------------------------- 1; __END__ =head1 NAME FCM::Example =head1 SYNOPSIS use FCM::Example; # ... do something with it =head1 DESCRIPTION This class/module does ... =head1 METHODS ... This section should be renamed FUNCTIONS for non-OO modules. =head1 DIAGNOSTICS ... =head1 CONFIGURATION AND ENVIRONMENT ... =head1 COPYRIGHT (C) Crown copyright Met Office. All rights reserved. =cut