Location.pm 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. package Fcm::Keyword::Entry::Location;
  9. use base qw{Fcm::Keyword::Entry};
  10. use Fcm::Keyword::Config;
  11. sub new {
  12. my ($class, $args_ref) = @_;
  13. if (!$args_ref) {
  14. $args_ref = {};
  15. }
  16. $args_ref = {
  17. browser_rev_template => undef,
  18. browser_url_template => undef,
  19. implied_entry_list => [],
  20. is_implied => 0,
  21. location_component_pattern => undef,
  22. revision_entries => Fcm::Keyword::Config::get_entries(
  23. 'REVISION_ENTRIES', $args_ref,
  24. ),
  25. %{$args_ref},
  26. },
  27. return bless({%{$args_ref}}, $class);
  28. }
  29. ################################################################################
  30. # Methods: get_*
  31. for my $key (
  32. # Returns a template for constructing the browser URL
  33. 'browser_url_template',
  34. # Returns a template for constructing the revision part in the browser URL
  35. 'browser_rev_template',
  36. # Returns a list of entries implied this entry
  37. 'implied_entry_list',
  38. # Returns the component pattern for a location matching this entry
  39. 'location_component_pattern',
  40. # Returns the entries for revision keywords
  41. 'revision_entries',
  42. ) {
  43. no strict qw{refs};
  44. my $getter = "get_$key";
  45. *$getter = sub {
  46. my ($self) = @_;
  47. return $self->{$key};
  48. }
  49. }
  50. ################################################################################
  51. # Returns true if this is an implied entry
  52. sub is_implied {
  53. my ($self) = @_;
  54. return $self->{is_implied};
  55. }
  56. 1;
  57. __END__
  58. =head1 NAME
  59. Fcm::Keyword::Entry::Location
  60. =head1 SYNOPSIS
  61. use Fcm::Keyword::Entry::Location;
  62. $entry = Fcm::Keyword::Entry::Location->new({
  63. key => $key, value => $value, # ...
  64. });
  65. $key = $entry->get_key();
  66. $value = $entry->get_value();
  67. $revision_entries = $entry->get_revision_entries();
  68. =head1 DESCRIPTION
  69. This is a sub-class of L<Fcm::Keyword::Entry|Fcm::Keyword::Entry>. An object of
  70. this class represents a FCM location keyword entry.
  71. =head1 METHODS
  72. See L<Fcm::Keyword::Entry|Fcm::Keyword::Entry> for inherited methods.
  73. =over 4
  74. =item new($args_ref)
  75. Constructor.
  76. =item get_browser_url_template()
  77. Returns the template string for constructing the browser URL. The string {1},
  78. {2}, {3}, etc in the template string will be substituted by the components
  79. captured by the location component pattern and the revision template. See
  80. C<get_url_component_pattern()> and C<get_browser_rev_template()>.
  81. =item get_browser_rev_template()
  82. Returns the template string for constructing the revision part of the browser
  83. URL. The string {1} in the template string will be substituted by the revision.
  84. See C<get_browser_url_template()>.
  85. =item get_implied_entry_list()
  86. Returns a list of entries implied by this entry.
  87. =item get_location_component_pattern()
  88. Returns a regular expression, when matched against the scheme-specific-part in
  89. the actual URI of a location in the namespace of this keyword entry, will
  90. capture a list of components, which can then be used to replace the numbered
  91. fields in the browser URL template. See C<get_browser_url_template()>.
  92. =item get_revision_entries()
  93. Returns a L<Fcm::Keyword::Entries|Fcm::Keyword::Entries> object containing the
  94. revision keyword entries of this location.
  95. =item is_implied()
  96. Returns true if this is an implied entry.
  97. =back
  98. =head1 TO DO
  99. Introduce a Fcm::Keyword::Config module to store entries constructor setting.
  100. =head1 SEE ALSO
  101. L<Fcm::Keyword|Fcm::Keyword>,
  102. L<Fcm::Keyword::Config|Fcm::Keyword::Config>,
  103. L<Fcm::Keyword::Entries|Fcm::Keyword::Entries>,
  104. L<Fcm::Keyword::Entry|Fcm::Keyword::Entry>
  105. =head1 COPYRIGHT
  106. E<169> Crown copyright Met Office. All rights reserved.
  107. =cut