=head1 NAME

CCL::ChangeList - Create and handle change lists

=head1 DESCRIPTION

This package is used by the current CCL API to handle change lists.

=cut

package CCL::ChangeList;

use strict;

=head2 CONSTRUCTORS

=head3 new

This is mostly used internally.

It might take a parameter with the CCL API which it references.  Not
sure if that's necessary.

=cut

sub new {
  my $this=shift;
  my $class=ref($this) || $this;
  my $self={
            changes => [],
           };
  bless $self, $class;

  $self;
}

=head2 REGISTERING CHANGES

=head3 change

This is the reciever for the change signal, see
C<CclDatabase::signalChange>.  Arguments therefore are

  $cl->change($path, $type, $new, $old);

=cut

sub change {
  my $self=shift;
  my $path=shift;
  my $type=shift;
  my $new=shift;
  my $old=shift;

  # we only care about parameter changes here
  return if $type;

  # for deleted objects, we'll have $new undefined.  TODO: I guess we
  # ignore those for a change list?
  return unless defined $new;

  push @{$self->{changes}}, "$path = $new";
  1;
}

=head2 API ACCESS

=head3 getList

Returns a reference to the internal change list.  Don't change it!
The API copies this list.

=cut

sub getList {
  my $self=shift;
  return $self->{changes};
}

=head3 clearList

Clears the current change list.

=cut

sub clearList {
  my $self=shift;
  $self->{changes} = [];
}

1;
