Skip to main content

sherlock_io/patterns/
perl.rs

1use regex::Regex;
2
3pub struct PerlPatterns {
4    external_patterns: Vec<Regex>,
5    cache_patterns: Vec<Regex>,
6    extensions: Vec<String>,
7}
8
9impl PerlPatterns {
10    pub fn new() -> Self {
11        let external_patterns = vec![
12            // CPAN build artifacts
13            Regex::new(r"blib/").unwrap(),
14            Regex::new(r"_build/").unwrap(),
15            Regex::new(r"Build$").unwrap(),
16            Regex::new(r"\.build/").unwrap(),
17            
18            // Module::Build artifacts
19            Regex::new(r"MYMETA\.yml").unwrap(),
20            Regex::new(r"MYMETA\.json").unwrap(),
21            Regex::new(r"META\.yml").unwrap(),
22            Regex::new(r"META\.json").unwrap(),
23            
24            // ExtUtils::MakeMaker artifacts
25            Regex::new(r"Makefile$").unwrap(),
26            Regex::new(r"Makefile\.old").unwrap(),
27            Regex::new(r"pm_to_blib").unwrap(),
28            
29            // PAR/PAR::Packer artifacts
30            Regex::new(r"\.par$").unwrap(),
31            Regex::new(r"\.pp$").unwrap(),
32            
33            // Perl archives
34            Regex::new(r"\.phar$").unwrap(),
35            
36            // Coverage
37            Regex::new(r"cover_db/").unwrap(),
38            Regex::new(r"\.gcov$").unwrap(),
39            
40            // Temporary files
41            Regex::new(r"\.tmp/").unwrap(),
42            Regex::new(r"tmp/").unwrap(),
43            Regex::new(r"\.swp$").unwrap(),
44            Regex::new(r"\.swo$").unwrap(),
45            Regex::new(r"~$").unwrap(),
46            
47            // Perl specific temp files
48            Regex::new(r"\.bak$").unwrap(),
49            Regex::new(r"\.orig$").unwrap(),
50            
51            // Carton (Perl dependency manager)
52            Regex::new(r"local/").unwrap(),
53            Regex::new(r"\.carton/").unwrap(),
54            
55            // Perlbrew
56            Regex::new(r"\.perlbrew/").unwrap(),
57            
58            // Dist::Zilla
59            Regex::new(r"\.build/").unwrap(),
60            
61            // Minilla
62            Regex::new(r"\.minilla/").unwrap(),
63            
64            // Logs
65            Regex::new(r"\.log$").unwrap(),
66            Regex::new(r"logs/").unwrap(),
67        ];
68
69        let cache_patterns = vec![
70            // Build cache
71            Regex::new(r"blib/").unwrap(),
72            Regex::new(r"_build/").unwrap(),
73            
74            // Coverage cache
75            Regex::new(r"cover_db/").unwrap(),
76            
77            // Carton cache
78            Regex::new(r"local/").unwrap(),
79            
80            // Dist::Zilla cache
81            Regex::new(r"\.build/").unwrap(),
82        ];
83
84        let extensions = vec![
85            // Perl source files
86            "pl".to_string(),
87            "pm".to_string(),
88            "pod".to_string(),
89            "t".to_string(),
90            
91            // Perl scripts
92            "perl".to_string(),
93            "cgi".to_string(),
94            
95            // Perl 6/Raku (for compatibility)
96            "p6".to_string(),
97            "pl6".to_string(),
98            "pm6".to_string(),
99            "raku".to_string(),
100            "rakumod".to_string(),
101            
102            // Configuration files
103            "yml".to_string(),
104            "yaml".to_string(),
105            "json".to_string(),
106            "ini".to_string(),
107            "conf".to_string(),
108            
109            // Documentation
110            "md".to_string(),
111            "rst".to_string(),
112            "txt".to_string(),
113            
114            // Web files (for Perl web apps)
115            "html".to_string(),
116            "css".to_string(),
117            "js".to_string(),
118            
119            // Shell scripts
120            "sh".to_string(),
121            "bash".to_string(),
122            
123            // SQL
124            "sql".to_string(),
125            
126            // XML
127            "xml".to_string(),
128        ];
129
130        Self {
131            external_patterns,
132            cache_patterns,
133            extensions,
134        }
135    }
136
137    pub fn get_external_patterns(&self) -> &[Regex] {
138        &self.external_patterns
139    }
140
141    pub fn get_cache_patterns(&self) -> &[Regex] {
142        &self.cache_patterns
143    }
144
145    pub fn get_extensions(&self) -> &[String] {
146        &self.extensions
147    }
148
149    pub fn get_script_names() -> Vec<&'static str> {
150        vec![
151            // CPAN files
152            "Makefile.PL", "Build.PL", "META.yml", "META.json",
153            "MYMETA.yml", "MYMETA.json", "MANIFEST", "MANIFEST.SKIP",
154            
155            // Carton files
156            "cpanfile", "cpanfile.snapshot",
157            
158            // Dist::Zilla
159            "dist.ini", "weaver.ini",
160            
161            // Minilla
162            "minil.toml",
163            
164            // App::cpm
165            "cpm.yml",
166            
167            // Perl version managers
168            ".perl-version", ".perlbrew",
169            
170            // Build files
171            "Makefile", "GNUmakefile", "makefile",
172            
173            // CI/CD
174            ".github/workflows/perl.yml",
175            ".travis.yml", "appveyor.yml",
176            
177            // Docker
178            "Dockerfile", "docker-compose.yml",
179            
180            // Editor
181            ".editorconfig", ".gitignore",
182            ".perltidyrc", ".perlcriticrc",
183            
184            // Scripts
185            "run.sh", "build.sh", "deploy.sh",
186            "install.sh", "test.sh",
187            
188            // Web server configs
189            ".htaccess", "httpd.conf",
190            
191            // Perl specific
192            "perllocal.pod", "perldoc.pod",
193        ]
194    }
195
196    pub fn get_common_directories() -> Vec<&'static str> {
197        vec![
198            // Source
199            "lib/", "bin/", "script/", "scripts/",
200            
201            // Tests
202            "t/", "test/", "tests/", "xt/",
203            
204            // Documentation
205            "doc/", "docs/", "eg/", "examples/",
206            
207            // Build
208            "blib/", "_build/", ".build/",
209            
210            // Dependencies
211            "local/", "extlib/", "fatlib/",
212            
213            // Web
214            "public/", "static/", "htdocs/", "www/",
215            "templates/", "views/",
216            
217            // Configuration
218            "config/", "conf/", "etc/",
219            
220            // Logs
221            "logs/", "log/",
222            
223            // Data
224            "data/", "share/",
225            
226            // Tools
227            "tools/", "util/", "utils/",
228            
229            // Resources
230            "res/", "resources/",
231        ]
232    }
233}