File Coverage

blib/lib/App/Sqitch/Plan/LineList.pm
Criterion Covered Total %
statement 32 32 100.0
branch n/a
condition n/a
subroutine 10 10 100.0
pod 7 7 100.0
total 49 49 100.0


line stmt bran cond sub pod time code
1              
2             use 5.010;
3 50     50   839 use strict;
  50         158  
4 50     50   253 use utf8;
  50         95  
  50         1223  
5 50     50   248  
  50         112  
  50         250  
6             our $VERSION = 'v1.3.0'; # VERSION
7              
8             my $class = shift;
9             my (@list, %index);
10 45     45 1 1804 for my $line (@_) {
11 45         96 push @list => $line;
12 45         138 $index{ $line } = $#list;
13 287         407 }
14 287         861  
15             return bless {
16             list => \@list,
17 45         889 lookup => \%index,
18             }
19             }
20              
21              
22             my ( $self, $line ) = @_;
23 3     3 1 11 my $list = $self->{list};
  3         19  
24 61     61 1 796 push @{ $list } => $line;
  61         319  
25 7     7 1 34 $self->{lookup}{$line} = $#$list;
26 44     44 1 202 }
27              
28             my ( $self, $line, $idx ) = @_;
29 43     43 1 1614  
30 43         89 # Add the line to the list.
31 43         66 my $list = $self->{list};
  43         96  
32 43         290 splice @{ $list }, $idx, 0, $line;
33              
34             # Reindex.
35             my $index = $self->{lookup};
36 19     19 1 435 $index->{ $list->[$_] } = $_ for $idx..$#$list;
37             return $self;
38             }
39 19         35  
40 19         28 1;
  19         49  
41              
42              
43 19         32 =head1 Name
44 19         108  
45 19         47 App::Sqitch::Plan::LineList - Sqitch deployment plan line list
46              
47             =head1 Synopsis
48              
49             my $list = App::Sqitch::Plan::LineList->new(@lines);
50              
51             my @lines = $list->items;
52             my $index = $list->index_of($line);
53              
54             $lines->append($another_line);
55              
56             =head1 Description
57              
58             This module is used internally by L<App::Sqitch::Plan> to manage plan file
59             lines. It's modeled on L<Array::AsHash>, but is much simpler and hews closer
60             to the API of L<App::Sqitch::Plan::ChangeList>.
61              
62             =head1 Interface
63              
64             =head2 Constructors
65              
66             =head3 C<new>
67              
68             my $plan = App::Sqitch::Plan::LineList->new(map { $_->name => @_ } @changes );
69              
70             Instantiates and returns a App::Sqitch::Plan::LineList object. The parameters
71             should be a key/value list of lines. Keys may be duplicated, as long as a tag
72             appears between each instance of a key.
73              
74             =head2 Instance Methods
75              
76             =head3 C<count>
77              
78             =head3 C<items>
79              
80             =head3 C<item_at>
81              
82             =head3 C<index_of>
83              
84             =head3 C<append>
85              
86             =head3 C<insert_at>
87              
88             =head1 See Also
89              
90             =over
91              
92             =item L<App::Sqitch::Plan>
93              
94             The Sqitch plan.
95              
96             =back
97              
98             =head1 Author
99              
100             David E. Wheeler <david@justatheory.com>
101              
102             =head1 License
103              
104             Copyright (c) 2012-2022 iovation Inc., David E. Wheeler
105              
106             Permission is hereby granted, free of charge, to any person obtaining a copy
107             of this software and associated documentation files (the "Software"), to deal
108             in the Software without restriction, including without limitation the rights
109             to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
110             copies of the Software, and to permit persons to whom the Software is
111             furnished to do so, subject to the following conditions:
112              
113             The above copyright notice and this permission notice shall be included in all
114             copies or substantial portions of the Software.
115              
116             THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
117             IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
118             FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
119             AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
120             LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
121             OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
122             SOFTWARE.
123              
124             =cut