[1980] | 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::CLI::Invoker::KeywordPrinter; |
---|
| 10 | use base qw{Fcm::CLI::Invoker}; |
---|
| 11 | |
---|
| 12 | use Carp qw{croak}; |
---|
| 13 | use Fcm::CLI::Exception; |
---|
| 14 | use Fcm::Keyword; |
---|
| 15 | use Fcm::Keyword::Formatter::Entries; |
---|
| 16 | use Fcm::Keyword::Formatter::Entry::Location; |
---|
| 17 | use Fcm::Keyword::Exception; |
---|
| 18 | use Fcm::Util qw{get_url_of_wc}; |
---|
| 19 | |
---|
| 20 | ################################################################################ |
---|
| 21 | # Invokes the sub-system |
---|
| 22 | sub invoke { |
---|
| 23 | my ($self) = @_; |
---|
| 24 | my @targets = $self->get_arguments(); |
---|
| 25 | if (@targets) { |
---|
| 26 | for my $target (@targets) { |
---|
| 27 | my $entry_list = Fcm::Keyword::get_location_entries_for($target); |
---|
| 28 | my $loc = $target; |
---|
| 29 | if (-e $target) { |
---|
| 30 | $loc = get_url_of_wc($target); |
---|
| 31 | if (!$loc) { |
---|
| 32 | croak(Fcm::Keyword::Exception->new({message => sprintf( |
---|
| 33 | "%s: unrecognised version control resource", $target, |
---|
| 34 | )})); |
---|
| 35 | } |
---|
| 36 | } |
---|
| 37 | my @entry_list = Fcm::Keyword::get_location_entries_for($loc); |
---|
| 38 | if (!@entry_list) { |
---|
| 39 | croak(Fcm::Keyword::Exception->new({message => sprintf( |
---|
| 40 | "%s: no FCM location keyword found for this target", $target, |
---|
| 41 | )})); |
---|
| 42 | } |
---|
| 43 | my $formatter = Fcm::Keyword::Formatter::Entry::Location->new(); |
---|
| 44 | for my $entry ( |
---|
| 45 | sort {$a->get_key() cmp $b->get_key()} |
---|
| 46 | grep {!$_->is_implied()} |
---|
| 47 | @entry_list |
---|
| 48 | ) { |
---|
| 49 | print($formatter->format($entry), "\n"); |
---|
| 50 | } |
---|
| 51 | } |
---|
| 52 | } |
---|
| 53 | else { |
---|
| 54 | my $formatter = Fcm::Keyword::Formatter::Entries->new(); |
---|
| 55 | print($formatter->format(Fcm::Keyword::get_entries())); |
---|
| 56 | } |
---|
| 57 | } |
---|
| 58 | |
---|
| 59 | 1; |
---|
| 60 | __END__ |
---|
| 61 | |
---|
| 62 | =head1 NAME |
---|
| 63 | |
---|
| 64 | Fcm::CLI::Invoker::KeywordPrinter |
---|
| 65 | |
---|
| 66 | =head1 SYNOPSIS |
---|
| 67 | |
---|
| 68 | use Fcm::CLI::Invoker::KeywordPrinter; |
---|
| 69 | $invoker = Fcm::CLI::Invoker::KeywordPrinter->new({ |
---|
| 70 | command => $command, |
---|
| 71 | options => \%options, |
---|
| 72 | arguments => $arguments, |
---|
| 73 | }); |
---|
| 74 | $invoker->invoke(); |
---|
| 75 | |
---|
| 76 | =head1 DESCRIPTION |
---|
| 77 | |
---|
| 78 | This class extends L<Fcm::CLI::Invoker|Fcm::CLI::Invoker> an inherits all its |
---|
| 79 | methods. An object of this class is used to invoke the location keyword printer. |
---|
| 80 | |
---|
| 81 | =head1 METHODS |
---|
| 82 | |
---|
| 83 | See L<Fcm::CLI::Invoker|Fcm::CLI::Invoker> for a list of inherited methods. |
---|
| 84 | |
---|
| 85 | =over 4 |
---|
| 86 | |
---|
| 87 | =item invoke() |
---|
| 88 | |
---|
| 89 | Invokes the location keyword printer. If a namespace is specified in the |
---|
| 90 | argument, prints revision keywords and browser mapping templates for the |
---|
| 91 | specified namespace. If a namespace is not specified, prints all registered |
---|
| 92 | location keywords. |
---|
| 93 | |
---|
| 94 | =back |
---|
| 95 | |
---|
| 96 | =head1 DIAGNOSTICS |
---|
| 97 | |
---|
| 98 | =over 4 |
---|
| 99 | |
---|
| 100 | =item L<Fcm::Keyword::Exception|Fcm::Keyword::Exception> |
---|
| 101 | |
---|
| 102 | The invoke() method can croak() with this exception if there is no matching |
---|
| 103 | namespace matching that of the specified. |
---|
| 104 | |
---|
| 105 | =back |
---|
| 106 | |
---|
| 107 | =head1 TO DO |
---|
| 108 | |
---|
| 109 | Unit tests. |
---|
| 110 | |
---|
| 111 | =head1 SEE ALSO |
---|
| 112 | |
---|
| 113 | L<Fcm::CLI::Exception|Fcm::CLI::Exception>, |
---|
| 114 | L<Fcm::CLI::Invoker|Fcm::CLI::Invoker>, |
---|
| 115 | L<Fcm::CLI::Subcommand|Fcm::CLI::Subcommand>, |
---|
| 116 | L<Fcm::Keyword|Fcm::Keyword>, |
---|
| 117 | L<Fcm::Keyword::Formatter::Entries|Fcm::Keyword::Formatter::Entries>, |
---|
| 118 | L<Fcm::Keyword::Formatter::Entry::Location|Fcm::Keyword::Formatter::Entry::Location> |
---|
| 119 | |
---|
| 120 | =head1 COPYRIGHT |
---|
| 121 | |
---|
| 122 | E<169> Crown copyright Met Office. All rights reserved. |
---|
| 123 | |
---|
| 124 | =cut |
---|