=head1 NAME

  CFX5::PatchInfo - Script access to point release and patch information

=head1 SYNOPSIS

  use CFX5::PatchInfo;
  my $patchinfo = CFX5::PatchInfo->new();
  my $patchtext = $patchinfo->get();
  my @patchtext = $patchinfo->get();

=head1 DESCRIPTION

The C<CFX5::PatchInfo> module provides script access to point release
and patch information, stored in a file in a standard location.

=cut

package CFX5::PatchInfo;

use strict;
use CFX5::FileOps qw(get_file_contents);
use CFX5::Config qw(%Config);
use CFX5::PathManip qw(join_file);
use CFX5::FileStat;

=head2 CONSTRUCTORS

=head3 new

Returns a new instance of this class and calls init() to initialise the object.

=cut

sub new
{
  my $this=shift;
  my $class=ref($this) || $this;
  my $self = {lines => undef};
  bless $self, $class;
  $self->init(@_);
  return $self;
}

=head3 init

Initialise the object from the master version number file, if it exists.
This file is expected to exist.

=cut


sub init
{
  my $self=shift;
  my $filename = join_file($Config{AWP_COMMON_FILES_ROOT},
                           'globalsettings', 'install_help_about.txt');
  return unless (test_f $filename);
  @{$self->{lines}} = split '[\n|\r]+', get_file_contents($filename);
  return;
}


=head3 is_nonempty

Returns 1 if the file exists and contains lines.
Otherwise returns 0;

=cut

sub is_nonempty
{
  my $self = shift;
  return 0 unless (defined $self->{lines});
  return 0 unless (scalar @{$self->{lines}} > 0);
  return 1;
}


=head3 get

Returns the help about information as a text string.
In list context, the list of lines is returned.

=cut

sub get
{
  my $self = shift;
  unless (wantarray)
  {
    return join("\n", @{$self->{lines}});
  }
  return @{$self->{lines}};
}

1;
