VCI::Abstract::FileContainer - Anything that can contain a


VCI documentation Contained in the VCI distribution.

Index


Code Index:

NAME

Top

VCI::Abstract::FileContainer - Anything that can contain a File or Directory.

DESCRIPTION

Top

This is a Moose::Role that represents anything that can hold files. Usually that's a VCI::Abstract::Directory.

METHODS

Top

Accessors

These accessors are all read-only.

contents

An arrayref of VCI::Abstract::Committable objects that we contain. The order is not guaranteed.

contents_history

The VCI::Abstract::History of all the items in this container. The History will contain information about all of the items inside the container, but possibly won't contain information about anything outside of the container.

This does not include the history of the item itself, if the item itself has a history. (That is, if this item is also a VCI::Abstract::Committable, you should use the history method to get information about this specific item.)

contents_history_recursive

The normal contents_history only returns the History of items directly contained in the directory.

This accsessor returns an entire VCI::Abstract::History for all items in the Project from this directory down.

So, for example, if dir1 contains dir2, and dir2 contains dir3, this method would return the History of all items contained in dir1, dir2, and dir3.

project

The VCI::Abstract::Project that this FileContainer belongs to.

SEE ALSO

Top

Implementors: VCI::Abstract::Directory and VCI::Abstract::Commit


VCI documentation Contained in the VCI distribution.

package VCI::Abstract::FileContainer;
use Moose::Role;

use VCI::Abstract::Committable; # This makes the Type Constraint work

# Unfortunately we can't currently enforce this, because Moose throws an
# error about attribute conflicts for a Directory, which is both a Committable
# and a FileContainer.
#with 'VCI::Abstract::ProjectItem';

has 'contents' => (is => 'ro', isa => 'ArrayRef[VCI::Abstract::Committable]',
                   lazy_build => 1);
has 'contents_history' => (is => 'ro', isa => 'VCI::Abstract::History',
                           lazy_build => 1);
has contents_history_recursive
    => (is => 'ro', isa => 'VCI::Abstract::History', lazy_build => 1);

# Unfortunately Moose is a little dumb about Roles sometimes, and requires
# our *abstract* classes to implement these, instead of our subclasses. So
# we can't really require them.
#requires 'build_contents';

sub _build_contents_history {
    my $self = shift;
    my @histories = map {$_->history} @{$self->contents};
    return $self->history_class->union(
        histories => \@histories, project => $self->project);
}

sub _build_contents_history_recursive {
    my $self = shift;
    my @histories;
    push(@histories, $self->contents_history);
    push(@histories, @{ _get_histories($self->contents) });
    return $self->history_class->union(
               histories => \@histories, project => $self->project);
}

# Helper for build_contents_history_recursive.
sub _get_histories {
    my ($items) = @_;
    my @histories;
    foreach my $item (@$items) {
        if ($item->does('VCI::Abstract::FileContainer')) {
            push(@histories, @{ _get_histories($item->contents) });
            push(@histories, $item->contents_history);
        }
    }
    return \@histories;
}

1;

__END__