New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
Base.pm in vendors/lib/FCM1 – NEMO

source: vendors/lib/FCM1/Base.pm @ 10669

Last change on this file since 10669 was 10669, checked in by nicolasmartin, 5 years ago

Import latest FCM release from Github into the repository for testing

File size: 3.4 KB
Line 
1# ------------------------------------------------------------------------------
2# (C) British Crown Copyright 2006-17 Met Office.
3#
4# This file is part of FCM, tools for managing and building source code.
5#
6# FCM is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# FCM is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with FCM. If not, see <http://www.gnu.org/licenses/>.
18# ------------------------------------------------------------------------------
19# NAME
20#   FCM1::Base
21#
22# DESCRIPTION
23#   This is base class for all FCM OO packages.
24#
25# ------------------------------------------------------------------------------
26
27package FCM1::Base;
28
29# Standard pragma
30use strict;
31use warnings;
32
33use FCM1::Config;
34
35my @scalar_properties = (
36  'config', # instance of FCM1::Config, configuration setting
37);
38
39# ------------------------------------------------------------------------------
40# SYNOPSIS
41#   $obj = FCM1::Base->new;
42#
43# DESCRIPTION
44#   This method constructs a new instance of the FCM1::Base class.
45# ------------------------------------------------------------------------------
46
47sub new {
48  my $this  = shift;
49  my %args  = @_;
50  my $class = ref $this || $this;
51
52  my $self  = {};
53  for (@scalar_properties) {
54    $self->{$_} = exists $args{uc ($_)} ? $args{uc ($_)} : undef;
55  }
56
57  bless $self, $class;
58  return $self;
59}
60
61# ------------------------------------------------------------------------------
62# SYNOPSIS
63#   $value = $obj->X;
64#   $obj->X ($value);
65#
66# DESCRIPTION
67#   Details of these properties are explained in @scalar_properties.
68# ------------------------------------------------------------------------------
69
70for my $name (@scalar_properties) {
71  no strict 'refs';
72
73  *$name = sub {
74    my $self = shift;
75
76    # Argument specified, set property to specified argument
77    if (@_) {
78      $self->{$name} = $_[0];
79    }
80
81    # Default value for property
82    if (not defined $self->{$name}) {
83      if ($name eq 'config') {
84        # Configuration setting of the main program
85        $self->{$name} = FCM1::Config->instance();
86      }
87    }
88
89    return $self->{$name};
90  }
91}
92
93# ------------------------------------------------------------------------------
94# SYNOPSIS
95#   $value = $self->setting (@args); # $self->config->setting
96#   $value = $self->verbose (@args); # $self->config->verbose
97# ------------------------------------------------------------------------------
98
99for my $name (qw/setting verbose/) {
100  no strict 'refs';
101
102  *$name = sub {
103    my $self = shift;
104    return $self->config->$name (@_);
105  }
106}
107
108# ------------------------------------------------------------------------------
109# SYNOPSIS
110#   $value = $self->cfglabel (@args);
111#
112# DESCRIPTION
113#   This is an alias to $self->config->setting ('CFG_LABEL', @args);
114# ------------------------------------------------------------------------------
115
116sub cfglabel {
117  my $self = shift;
118  return $self->setting ('CFG_LABEL', @_);
119}
120
121# ------------------------------------------------------------------------------
122
1231;
124
125__END__
Note: See TracBrowser for help on using the repository browser.