Skip to content

Commit cbba49e

Browse files
committed
factor out finding the position of the section in both the master and the delta
1 parent 2f072f7 commit cbba49e

File tree

1 file changed

+13
-32
lines changed

1 file changed

+13
-32
lines changed

Porting/merge-deltas.pl

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ ( $tree, $directive, $pos = 0 )
4242
return; # not found
4343
}
4444

45+
sub find_pos_in ( $master, $delta, $title ) {
46+
return
47+
map header_pos( $_, 1, $title ),
48+
$master, $delta;
49+
}
50+
4551
sub inject_items ( $master, $master_pos, $delta, $delta_pos ) {
4652

4753
# find the =over in both
@@ -60,11 +66,7 @@ ( $master, $master_pos, $delta, $delta_pos )
6066

6167
# [ List each enhancement as a =head2 entry ]
6268
head2 => sub ( $master, $title, $delta ) {
63-
64-
# find the section in the delta and master
65-
my ( $master_pos, $delta_pos ) =
66-
map header_pos( $_, 1, $title ),
67-
$master, $delta;
69+
my ( $master_pos, $delta_pos ) = find_pos_in( $master, $delta, $title );
6870

6971
# find the first =head2, until the next =head1
7072
my $from = next_header_pos( $delta, 2, $delta_pos );
@@ -77,11 +79,7 @@ ( $master, $master_pos, $delta, $delta_pos )
7779

7880
# copy =head3 sections from known =head2 ones
7981
head3 => sub ( $master, $title, $delta ) {
80-
81-
# find the section in the delta and master
82-
my ( $master_pos, $delta_pos ) =
83-
map header_pos( $_, 1, $title ),
84-
$master, $delta;
82+
my ( $master_pos, $delta_pos ) = find_pos_in( $master, $delta, $title );
8583

8684
# loop over the =head2 in the section
8785
while ( $delta_pos = next_header_pos( $delta, 2, $delta_pos ) ) {
@@ -120,22 +118,13 @@ ( $master, $master_pos, $delta, $delta_pos )
120118

121119
# [ List each improvement as an =item entry ]
122120
item => sub ( $master, $title, $delta ) {
123-
124-
# find the section in the delta and master
125-
my ( $master_pos, $delta_pos ) =
126-
map header_pos( $_, 1, $title ),
127-
$master, $delta;
128-
129-
inject_items ( $master, $master_pos, $delta, $delta_pos );
121+
my ( $master_pos, $delta_pos ) = find_pos_in( $master, $delta, $title );
122+
inject_items( $master, $master_pos, $delta, $delta_pos );
130123
},
131124

132125
# =item entries inside a =head3
133126
item_head3 => sub ( $master, $title, $delta ) {
134-
135-
# find the section in the delta and master
136-
my ( $master_pos, $delta_pos ) =
137-
map header_pos( $_, 1, $title ),
138-
$master, $delta;
127+
my ( $master_pos, $delta_pos ) = find_pos_in( $master, $delta, $title );
139128

140129
# loop over the =head2 in the section
141130
while ( $delta_pos = next_header_pos( $delta, 2, $delta_pos ) ) {
@@ -157,11 +146,7 @@ ( $master, $master_pos, $delta, $delta_pos )
157146

158147
# copy the whole section content
159148
copy => sub ( $master, $title, $delta ) {
160-
161-
# find the section in the delta and master
162-
my ( $master_pos, $delta_pos ) =
163-
map header_pos( $_, 1, $title ),
164-
$master, $delta;
149+
my ( $master_pos, $delta_pos ) = find_pos_in( $master, $delta, $title );
165150

166151
# find the end of the section in the delta
167152
my $end_pos = next_header_pos( $delta, 1, $delta_pos ) - 1;
@@ -173,11 +158,7 @@ ( $master, $master_pos, $delta, $delta_pos )
173158

174159
# this one is very specific: 'Module removals' is treated separately
175160
deprecations => sub ( $master, $title, $delta ) {
176-
177-
# find the section in the delta and master
178-
my ( $master_pos, $delta_pos ) =
179-
map header_pos( $_, 1, $title ),
180-
$master, $delta;
161+
my ( $master_pos, $delta_pos ) = find_pos_in( $master, $delta, $title );
181162

182163
# loop over the =head2 in the section
183164
while ( $delta_pos = next_header_pos( $delta, 2, $delta_pos ) ) {

0 commit comments

Comments
 (0)