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 | # ------------------------------------------------------------------------------ |
---|
6 | use strict; |
---|
7 | use warnings; |
---|
8 | |
---|
9 | package Fcm::Keyword::Loader::Config::Location; |
---|
10 | |
---|
11 | use Fcm::Config; |
---|
12 | |
---|
13 | my %IMPLIED_NAMESPACE_SUFFIX = (tr => 'trunk', br => 'branches', tg => 'tags'); |
---|
14 | |
---|
15 | sub new { |
---|
16 | my ($class) = @_; |
---|
17 | return bless(\do{my $annon_scalar}, $class); |
---|
18 | } |
---|
19 | |
---|
20 | ################################################################################ |
---|
21 | # Returns 'Fcm::Config' |
---|
22 | sub get_source { |
---|
23 | my ($self) = @_; |
---|
24 | return 'Fcm::Config'; |
---|
25 | } |
---|
26 | |
---|
27 | ################################################################################ |
---|
28 | # Loads location keywords from Fcm::Config to $entries |
---|
29 | sub 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 | |
---|
69 | 1; |
---|
70 | __END__ |
---|
71 | |
---|
72 | =head1 NAME |
---|
73 | |
---|
74 | Fcm::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 | |
---|
83 | This class implements the L<Fcm::Keyword::Loader|Fcm::Keyword::Loader> |
---|
84 | interface. |
---|
85 | |
---|
86 | Loads location keywords from L<Fcm::Config|Fcm::Config> into a |
---|
87 | L<Fcm::Keyword::Entries|Fcm::Keyword::Entries> object containing |
---|
88 | L<Fcm::Keyword::Entry::Location|Fcm::Keyword::Entry::Location> objects. |
---|
89 | |
---|
90 | =head1 METHODS |
---|
91 | |
---|
92 | =over 4 |
---|
93 | |
---|
94 | =item new() |
---|
95 | |
---|
96 | Constructor. |
---|
97 | |
---|
98 | =item get_source() |
---|
99 | |
---|
100 | Returns the string "L<Fcm::Config|Fcm::Config>". |
---|
101 | |
---|
102 | =item load_to($entries) |
---|
103 | |
---|
104 | Loads 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 |
---|
106 | true on success. (However, if L<Fcm::Config|Fcm::Config> is initialising, |
---|
107 | returns false to force a reload next time.) |
---|
108 | |
---|
109 | =back |
---|
110 | |
---|
111 | =head1 TO DO |
---|
112 | |
---|
113 | Need a more flexible system for implied keywords. |
---|
114 | |
---|
115 | =head1 SEE ALSO |
---|
116 | |
---|
117 | L<Fcm::Config|Fcm::Config>, |
---|
118 | L<Fcm::Keyword|Fcm::Keyword>, |
---|
119 | L<Fcm::Keyword::Entries|Fcm::Keyword::Entries>, |
---|
120 | L<Fcm::Keyword::Entry|Fcm::Keyword::Entry>, |
---|
121 | L<Fcm::Keyword::Loader|Fcm::Keyword::Loader>, |
---|
122 | L<Fcm::Keyword::Loader::Config::Revision|Fcm::Keyword::Loader::Config::Revision> |
---|
123 | |
---|
124 | =head1 COPYRIGHT |
---|
125 | |
---|
126 | E<169> Crown copyright Met Office. All rights reserved. |
---|
127 | |
---|
128 | =cut |
---|