source: branches/UKMO/r6232_tracer_advection/NEMOGCM/EXTERNAL/fcm/lib/Fcm/Keyword/Loader/Config/Location.pm

Last change on this file was 9295, checked in by jcastill, 3 years ago

Remove svn keywords

File size: 3.7 KB
Line 
1# ------------------------------------------------------------------------------
2# (C) Crown copyright Met Office. All rights reserved.
3# For further details please refer to the file COPYRIGHT.txt
4# which you should have received as part of this distribution.
5# ------------------------------------------------------------------------------
6use strict;
7use warnings;
8
9package Fcm::Keyword::Loader::Config::Location;
10
11use Fcm::Config;
12
13my %IMPLIED_NAMESPACE_SUFFIX = (tr => 'trunk', br => 'branches', tg => 'tags');
14
15sub new {
16    my ($class) = @_;
17    return bless(\do{my $annon_scalar}, $class);
18}
19
20################################################################################
21# Returns 'Fcm::Config'
22sub get_source {
23    my ($self) = @_;
24    return 'Fcm::Config';
25}
26
27################################################################################
28# Loads location keywords from Fcm::Config to $entries
29sub load_to {
30    my ($self, $entries) = @_;
31    my $config = $self->get_source()->instance();
32    my $load_counter = 0;
33    for my $key (keys(%{$config->setting('URL')})) {
34        my $value = $config->setting('URL', $key);
35        my $location_component_pattern = $config->setting(
36            'URL_BROWSER_MAPPING', $key, 'LOCATION_COMPONENT_PATTERN');
37        my $browser_url_template = $config->setting(
38            'URL_BROWSER_MAPPING', $key, 'BROWSER_URL_TEMPLATE');
39        my $browser_rev_template = $config->setting(
40            'URL_BROWSER_MAPPING', $key, 'BROWSER_REV_TEMPLATE');
41        my $entry = $entries->add_entry(
42            $key,
43            $value,
44            {
45                location_component_pattern => $location_component_pattern,
46                browser_url_template       => $browser_url_template,
47                browser_rev_template       => $browser_rev_template,
48            },
49        );
50        $load_counter++;
51
52        # Set up implied keywords
53        for my $suffix (keys(%IMPLIED_NAMESPACE_SUFFIX)) {
54            my $value_suf = $value . '/' . $IMPLIED_NAMESPACE_SUFFIX{$suffix};
55            for my $join (q{_}, q{-}) {
56                my $implied_entry = $entries->add_entry(
57                    uc($key . $join . $suffix),
58                    $value_suf,
59                    {is_implied => 1},
60                );
61                push(@{$entry->get_implied_entry_list()}, $implied_entry);
62                $load_counter++;
63            }
64        }
65    }
66    return ($config->is_initialising() ? 0 : defined($load_counter));
67}
68
691;
70__END__
71
72=head1 NAME
73
74Fcm::Keyword::Loader::Config::Location
75
76=head1 SYNOPSIS
77
78    $loader = Fcm::Keyword::Loader::Config::Location->new();
79    $loader->load_to($entries);
80
81=head1 DESCRIPTION
82
83This class implements the L<Fcm::Keyword::Loader|Fcm::Keyword::Loader>
84interface.
85
86Loads location keywords from L<Fcm::Config|Fcm::Config> into a
87L<Fcm::Keyword::Entries|Fcm::Keyword::Entries> object containing
88L<Fcm::Keyword::Entry::Location|Fcm::Keyword::Entry::Location> objects.
89
90=head1 METHODS
91
92=over 4
93
94=item new()
95
96Constructor.
97
98=item get_source()
99
100Returns the string "L<Fcm::Config|Fcm::Config>".
101
102=item load_to($entries)
103
104Loads location keywords and implied keywords from L<Fcm::Config|Fcm::Config> to
105$entries. It also loads settings for mapping location to browser URL. Returns
106true on success. (However, if L<Fcm::Config|Fcm::Config> is initialising,
107returns false to force a reload next time.)
108
109=back
110
111=head1 TO DO
112
113Need a more flexible system for implied keywords.
114
115=head1 SEE ALSO
116
117L<Fcm::Config|Fcm::Config>,
118L<Fcm::Keyword|Fcm::Keyword>,
119L<Fcm::Keyword::Entries|Fcm::Keyword::Entries>,
120L<Fcm::Keyword::Entry|Fcm::Keyword::Entry>,
121L<Fcm::Keyword::Loader|Fcm::Keyword::Loader>,
122L<Fcm::Keyword::Loader::Config::Revision|Fcm::Keyword::Loader::Config::Revision>
123
124=head1 COPYRIGHT
125
126E<169> Crown copyright Met Office. All rights reserved.
127
128=cut
Note: See TracBrowser for help on using the repository browser.