App::Sqitch::Plan::ChangeList(3pm)

Name
App::Sqitch::Plan::ChangeList - Sqitch deployment plan change list

Synopsis
  my $list = App::Sqitch::Plan::ChangeList->new(
      $add_roles,
      $add_users,
      $insert_user,
      $insert_user2,
  );

  my @changes = $list->changes;
  my $add_users = $list->change_at(1);
  my $add_users = $list->get('add_users');

  my $insert_user1 = $list->get('insert_user@alpha');
  my $insert_user2 = $list->get('insert_user');

Description
This module is used internally by App::Sqitch::Plan to manage plan changes. It's modeled on Array::AsHash and Hash::MultiValue, but makes allowances for finding changes relative to tags.

Interface

  Constructors
"new"

  my $plan = App::Sqitch::Plan::ChangeList->new( @changes );

Instantiates and returns a App::Sqitch::Plan::ChangeList object with the list of changes. Each change should be a App::Sqitch::Plan::Change object. Order will be preserved but the location of each change will be indexed by its name and ID, as well as the names and IDs of any associated tags.

  Instance Methods
"count"

  my $count = $changelist->count;

Returns the number of changes in the list.

"changes"

  my @changes = $changelist->changes;

Returns all of the changes in the list.

"tags"

  my @tags = $changelist->tags;

Returns all of the tags associated with changes in the list.

"items"

  my @changes = $changelist->items;

An alias for "changes".

"change_at"

  my $change = $change_list->change_at(10);

Returns the change at the specified index.

"index_of"

  my $index = $changelist->index_of($change_id);
  my $index = $changelist->index_of($change_name);

Returns the index of the change with the specified ID or name. The value passed may be one of these forms:

•   An ID

      my $index = $changelist->index_of('6c2f28d125aff1deea615f8de774599acf39a7a1');

    This is the SHA1 ID of a change or tag. Currently, the full 40-character hexed hash string must be specified.

•   A change name

      my $index = $changelist->index_of('users_table');

    The name of a change. Will throw an exception if the more than one change in the list goes by that name.

•   A tag name

      my $index = $changelist->index_of('@beta1');

    The name of a tag, including the leading "@".

•   A tag-qualified change name

      my $index = $changelist->index_of('users_table@beta1');

    The named change as it was last seen in the list before the specified tag.

"first_index_of"

  my $index = $changelist->first_index_of($change_name);
  my $index = $changelist->first_index_of($change_name, $name);

Returns the index of the first instance of the named change in the list. If a second argument is passed, the index of the first instance of the change after the index of the second argument will be returned. This is useful for getting the index of a change as it was deployed after a particular tag, for example:

  my $index = $changelist->first_index_of('foo', '@beta');
  my $index = $changelist->first_index_of('foo', 'users_table@beta1');

The second argument must unambiguously refer to a single change in the list. As such, it should usually be a tag name or tag-qualified change name. Returns "undef" if the change does not appear in the list, or if it does not appear after the specified second argument change name.

"last_change"

  my $change = $changelist->last_change;

Returns the last change to be appear in the list. Returns "undef" if the list contains no changes.

"last_tagged_change"

  my $change = $changelist->last_tagged_change;

Returns the last tagged change in the list. Returns "undef" if the list contains no tagged changes.

"index_of_last_tagged"

  my $index = $changelist->index_of_last_tagged;

Returns the index of the last tagged change in the list. Returns "undef" if the list contains no tags.

"get"

  my $change = $changelist->get($id);
  my $change = $changelist->get($change_name);
  my $change = $changelist->get($tag_name);

Returns the change for the specified ID or name. The name may be specified as described for index_of(). An exception will be thrown if more than one change goes by a specified name. As such, it is best to specify it as unambiguously as possible: as a tag name, a tag-qualified change name, or an ID.

"contains"

  say 'Yes!' if $plan->contains('6c2f28d125aff1deea615f8de774599acf39a7a1');

Like index_of(), but never throws an exception, and returns true if the plan contains the specified change, and false if it does not.

"find"

  my $change = $changelist->find($id);
  my $change = $changelist->find($change_name);
  my $change = $changelist->find($tag_name);
  my $change = $changelist->find("$change_name\@$tag_name");

Tries to find and return a change based on the argument. If no tag is specified, finds and returns the first instance of the named change. Otherwise, it returns the change as of the specified tag. Unlike get(), it will not throw an error if more than one change exists with the specified name, but will return the first instance.

"append"

  $changelist->append(@changes);

Append one or more changes to the list. Does not check for duplicates, so use with care.

"index_tag"

  $changelist->index_tag($index, $tag);

Index the tag at the specified index. That is, the tag is assumed to be associated with the change at the specified index, and so the internal look up table is updated so that the change at that index can be found via the tag's name and ID.

See Also

App::Sqitch::Plan
    The Sqitch plan.

Author
David E. Wheeler <david@justatheory.com>

License
Copyright (c) 2012-2025 David E. Wheeler, 2012-2021 iovation Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.