Bugzilla – Attachment 135804 Details for
Bug 30926
Remove unnecessary use statements
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 30926: [DO NOT PUSH] Yet another script
Bug-30926-DO-NOT-PUSH-Yet-another-script.patch (text/plain), 2.03 KB, created by
Jonathan Druart
on 2022-06-08 13:31:30 UTC
(
hide
)
Description:
Bug 30926: [DO NOT PUSH] Yet another script
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2022-06-08 13:31:30 UTC
Size:
2.03 KB
patch
obsolete
>From 38eec49e25ca466179305c4b4d432e58a9594bb7 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Wed, 8 Jun 2022 15:25:23 +0200 >Subject: [PATCH] Bug 30926: [DO NOT PUSH] Yet another script > >--- > remove_unused_import.pl | 50 +++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 50 insertions(+) > create mode 100644 remove_unused_import.pl > >diff --git a/remove_unused_import.pl b/remove_unused_import.pl >new file mode 100644 >index 00000000000..0a6fe63fd20 >--- /dev/null >+++ b/remove_unused_import.pl >@@ -0,0 +1,50 @@ >+#!/usr/bin/perl >+ >+use Modern::Perl; >+ >+use File::Slurp qw( read_file write_file ); >+ >+my @files = @ARGV; >+my $i; >+my $total = scalar @files; >+my $num_width = length $total; >+for my $file ( @files ) { >+ print sprintf "|%-25s| %${num_width}s / %s (%.2f%%)\r", >+ '=' x (24*$i++/$total). '>', >+ $i, $total, 100*$i/+$total; >+ flush STDOUT; >+ >+ my $content = read_file( $file ); >+ my ( $no_export_modules, $modules_used, $package_name ); >+ for my $line ( split "\n", $content ) { >+ if ( $line =~ m{^package C4::(.*);} ) { >+ $package_name = $1; >+ next; >+ } elsif ( $line =~ m{^use C4::([^\s]*);$} ) { >+ next; >+ } elsif ( $line =~ m{C4::([^\s\(\)-]*)} ) { >+ my $module = $1; >+ my $namespace_module = "C4::${module}::"; >+ if ( $line =~ m[$namespace_module] ) { >+ my @parts = split '::', $module; >+ pop @parts if @parts > 1; >+ $module = join '::', @parts; >+ } >+ $modules_used->{$module}++; >+ } >+ } >+ >+ my $new_content; >+ for my $line ( split "\n", $content ) { >+ if ( $line =~ m{^use C4::([^\s]*);$} ) { >+ next >+ if (!$package_name || $package_name ne $1) >+ && !exists $modules_used->{$1}; >+ } >+ $new_content .= "$line\n"; >+ } >+ if ( $content ne $new_content ) { >+ say "$file -- Modified"; >+ write_file($file, $new_content); >+ } >+} >-- >2.25.1
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 30926
: 135804 |
135805
|
135806
|
136250
|
136251
|
138795