aboutsummaryrefslogtreecommitdiff
path: root/t/prep.pl
blob: e2fe9bf1b776e6cb98afa35bf07d38dd5873408d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/perl

use strict;
use warnings FATAL => 'all';
use File::Copy;
use Tie::File;

chomp (my $pwd = `pwd`);
mkdir "$pwd/SBO" unless -d "$pwd/SBO";
copy ('/home/d4wnr4z0r/projects/sbotools/SBO-Lib/lib/SBO/Lib.pm', "$pwd/SBO");
my @subs;
open my $file_h, '<', "$pwd/SBO/Lib.pm";
my $regex = qr/^sub\s+([^\s]+)\s+/;
while (my $line = <$file_h>) {
	if (my $sub = ($line =~ $regex)[0]) {
		push @subs, $sub;
	}
}

seek $file_h, 0, 0;
my @not_exported;                                                               
FIRST: for my $sub (@subs) {                                                    
	my $found = 'FALSE';                                                        
	my $has = 'FALSE';                                                          
	SECOND: while (my $line = <$file_h>) {
		if ($found eq 'FALSE') {                                                
			$found = 'TRUE', next SECOND if $line =~ /\@EXPORT/;
		} else {                                                                
			last SECOND if $line =~ /^\);$/;                                    
			$has = 'TRUE', last SECOND if $line =~ /$sub/;
		}       
	}   
	push @not_exported, $sub unless $has eq 'TRUE';
	seek $file_h, 0, 0;
}

close $file_h;
tie my @file, 'Tie::File', "$pwd/SBO/Lib.pm";
FIRST: for my $line (@file) {
	if ($line =~ /\@EXPORT/) {
		$line = "our \@EXPORT = qw(". join ' ', @not_exported;
	}
	$line = "#$line" if $line =~ /root privileges/;
}