use v5.14; use strict; use warnings; package Pantry::Role::Runlist; # ABSTRACT: A role to manage entries in a run_list our $VERSION = '0.007'; # VERSION use Moose::Role; use namespace::autoclean; has run_list => ( is => 'bare', isa => 'ArrayRef[Str]', traits => ['Array'], default => sub { [] }, handles => { run_list => 'elements', _push_run_list => 'push', _clear_run_list => 'clear', }, ); sub in_run_list { my ($self, $item) = @_; return grep { $item eq $_ } $self->run_list; } sub append_to_run_list { my ($self, @items) = @_; for my $i (@items) { $self->_push_run_list($i) unless $self->in_run_list($i); } return; } sub remove_from_run_list { my ($self, @items) = @_; my %match = map { $_ => 1 } @items; my @keep = grep { ! $match{$_} } $self->run_list; $self->_clear_run_list; $self->_push_run_list(@keep); return; } 1; __END__ =pod =head1 NAME Pantry::Role::Runlist - A role to manage entries in a run_list =head1 VERSION version 0.007 =head1 DESCRIPTION This is a L that provides a C attribute and associated handlers to the class that consumes it. =head1 METHODS =head2 C for my $item ( $node->run_list ) { ... } Returns a list of items in the C =head2 C if ( $node->in_run_list("recipe[nginx]") ) { ... } Tests whether an item is contained in the C. =head2 C $node->append_to_run_list( @items ); Appends a list of items to the C. =head2 C $node->remove_from_run_list( @items ); Removes a list of items from the C. =head1 AUTHOR David Golden =head1 COPYRIGHT AND LICENSE This software is Copyright (c) 2011 by David Golden. This is free software, licensed under: The Apache License, Version 2.0, January 2004 =cut