Skip to content

Commit c99cdd6

Browse files
committed
factor out the injection of items
1 parent 8693f41 commit c99cdd6

File tree

1 file changed

+16
-30
lines changed

1 file changed

+16
-30
lines changed

Porting/merge-deltas.pl

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

45+
sub inject_items ( $master, $master_pos, $delta, $delta_pos ) {
46+
47+
# find the =over in both
48+
my ( $master_list_pos, $delta_list_pos ) = (
49+
next_directive_pos( $master, 'over-bullet', $master_pos ),
50+
next_directive_pos( $delta, 'over-bullet', $delta_pos )
51+
);
52+
53+
# inject the list from delta into the master
54+
push $master->[$master_list_pos]->@*,
55+
$delta->[$delta_list_pos]->@[ 2 .. $delta->[$delta_list_pos]->$#* ];
56+
}
57+
4558
# handlers for different section types
4659
my %handler = (
4760

@@ -113,16 +126,7 @@ ( $tree, $directive, $pos = 0 )
113126
map header_pos( $_, 1, $title ),
114127
$master, $delta;
115128

116-
# find the =over in both
117-
my ( $master_list_pos, $delta_list_pos ) = (
118-
next_directive_pos( $master, 'over-bullet', $master_pos ),
119-
next_directive_pos( $delta, 'over-bullet', $delta_pos )
120-
);
121-
122-
# inject the list from delta into the master
123-
push $master->[$master_list_pos]->@*,
124-
$delta->[$delta_list_pos]
125-
->@[ 2 .. $delta->[$delta_list_pos]->$#* ];
129+
inject_items ( $master, $master_pos, $delta, $delta_pos );
126130
},
127131

128132
# =item entries inside a =head3
@@ -146,16 +150,7 @@ ( $tree, $directive, $pos = 0 )
146150
$master_pos = # find the same =head2 in the master
147151
header_pos( $master, 3, $section_title, $master_pos );
148152

149-
# find the =over in both
150-
my ( $master_list_pos, $delta_list_pos ) = (
151-
next_directive_pos( $master, 'over-bullet', $master_pos ),
152-
next_directive_pos( $delta, 'over-bullet', $delta_pos )
153-
);
154-
155-
# inject the list from delta into the master
156-
push $master->[$master_list_pos]->@*,
157-
$delta->[$delta_list_pos]
158-
->@[ 2 .. $delta->[$delta_list_pos]->$#* ];
153+
inject_items( $master, $master_pos, $delta, $delta_pos );
159154
}
160155
}
161156
},
@@ -191,16 +186,7 @@ ( $tree, $directive, $pos = 0 )
191186
$master_pos = # find the same =head2 in the master
192187
header_pos( $master, 2, $section_title, $master_pos );
193188

194-
# find the =over in both
195-
my ( $master_list_pos, $delta_list_pos ) = (
196-
next_directive_pos( $master, 'over-text', $master_pos ),
197-
next_directive_pos( $delta, 'over-text', $delta_pos )
198-
);
199-
200-
# inject the list from delta into the master
201-
push $master->[$master_list_pos]->@*,
202-
$delta->[$delta_list_pos]
203-
->@[ 2 .. $delta->[$delta_list_pos]->$#* ];
189+
inject_items( $master, $master_pos, $delta, $delta_pos );
204190
}
205191
else {
206192
# find where the =head2 ends

0 commit comments

Comments
 (0)