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::VC::Revision; |
---|
10 | |
---|
11 | use Fcm::Util qw{run_command}; |
---|
12 | |
---|
13 | sub new { |
---|
14 | my ($class, $args_ref) = @_; |
---|
15 | return bless({%{$args_ref}}, $class); |
---|
16 | } |
---|
17 | |
---|
18 | ################################################################################ |
---|
19 | # Returns the VC location where revision keywords will be loaded from |
---|
20 | sub get_source { |
---|
21 | my ($self) = @_; |
---|
22 | return $self->{source}; |
---|
23 | } |
---|
24 | |
---|
25 | ################################################################################ |
---|
26 | # Loads revision keywords from $self->get_source() to $entries |
---|
27 | sub load_to { |
---|
28 | my ($self, $entries) = @_; |
---|
29 | my @lines = run_command( |
---|
30 | [qw{svn pg fcm:revision}, $self->get_source()], |
---|
31 | DEVNULL => 1, |
---|
32 | ERROR => 'ignore', |
---|
33 | METHOD => 'qx', |
---|
34 | ); |
---|
35 | my $load_counter = 0; |
---|
36 | for my $line (@lines) { |
---|
37 | chomp($line); |
---|
38 | my ($key, $value) = split(qr{\s+ = \s+}xms, $line); |
---|
39 | if ($key && $value) { |
---|
40 | $entries->add_entry($key, $value); |
---|
41 | $load_counter++; |
---|
42 | } |
---|
43 | } |
---|
44 | return defined($load_counter); |
---|
45 | } |
---|
46 | |
---|
47 | 1; |
---|
48 | __END__ |
---|
49 | |
---|
50 | =head1 NAME |
---|
51 | |
---|
52 | Fcm::Keyword::Loader::VC::Revision |
---|
53 | |
---|
54 | =head1 SYNOPSIS |
---|
55 | |
---|
56 | $loader = Fcm::Keyword::Loader::VC::Revision->new({source => $source}); |
---|
57 | $loader->load_to($entries); |
---|
58 | |
---|
59 | =head1 DESCRIPTION |
---|
60 | |
---|
61 | Loads revision keywords from a VC location into a |
---|
62 | L<Fcm::Keyword::Entries|Fcm::Keyword::Entries> object containing |
---|
63 | L<Fcm::Keyword::Entry|Fcm::Keyword::Entry> objects. |
---|
64 | |
---|
65 | =head1 METHODS |
---|
66 | |
---|
67 | =over 4 |
---|
68 | |
---|
69 | =item C<new({source =E<gt> $source})> |
---|
70 | |
---|
71 | Constructor. The argument $source is the VC location from which revision |
---|
72 | keywords will be loaded from. |
---|
73 | |
---|
74 | =item get_source() |
---|
75 | |
---|
76 | Returns the source VC location from which revision keywords will be loaded |
---|
77 | from. |
---|
78 | |
---|
79 | =item load_to($entries) |
---|
80 | |
---|
81 | Loads revision keywords from C<$self-E<gt>get_source()> to $entries. |
---|
82 | |
---|
83 | =back |
---|
84 | |
---|
85 | =head1 TO DO |
---|
86 | |
---|
87 | Abstract away the call to the VC system, which assumes the Subversion shell |
---|
88 | client at the moment. |
---|
89 | |
---|
90 | =head1 SEE ALSO |
---|
91 | |
---|
92 | L<Fcm::Keyword|Fcm::Keyword>, |
---|
93 | L<Fcm::Keyword::Entries|Fcm::Keyword::Entries>, |
---|
94 | L<Fcm::Keyword::Entry|Fcm::Keyword::Entry>, |
---|
95 | L<Fcm::Keyword::Entry::Location|Fcm::Keyword::Entry::Location>, |
---|
96 | L<Fcm::Keyword::Loader|Fcm::Keyword::Loader>, |
---|
97 | L<Fcm::Keyword::Loader::Config::Revision|Fcm::Keyword::Loader::Config::Revision> |
---|
98 | |
---|
99 | =head1 COPYRIGHT |
---|
100 | |
---|
101 | E<169> Crown copyright Met Office. All rights reserved. |
---|
102 | |
---|
103 | =cut |
---|