runitx Claude Opus 5.5 commited on
Commit
1ca425c
·
unverified ·
1 Parent(s): 805e74c

Extract VFS escape helpers into Shutter::App::Escape

Browse files

Moved escape_string, unescape_string, unescape_string_for_display and
escape_path_string verbatim into an Exporter module. They use no globals,
so no wrappers: bin/shutter requires the module after Shutter::Upload::FTP
(the lib path is unknown at their old spot) and imports all four names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

bin/shutter CHANGED
@@ -122,42 +122,9 @@ use Sort::Naturally;
122
 
123
  use English;
124
 
125
- sub escape_string {
126
- return $_[0];
127
-
128
- # used to be Gnome2::VFS->escape_string.
129
- my $ret = Gnome2::VFS->escape_string($_[0]);
130
- say "VFS escape_string $_[0] -> $ret";
131
- return $ret;
132
- }
133
-
134
- sub unescape_string {
135
- return $_[0];
136
-
137
- # used to be Gnome2::VFS->unescape_string.
138
- # at least, transform utf-8 to internal perl format for utf8
139
- my $ret = Gnome2::VFS->unescape_string($_[0]);
140
- say "VFS unescape_string $_[0] -> $ret";
141
- return $ret;
142
- }
143
-
144
- sub unescape_string_for_display {
145
- return $_[0];
146
-
147
- # used to be Gnome2::VFS->unescape_string_for_display.
148
- my $ret = Gnome2::VFS->unescape_string_for_display($_[0]);
149
- say "VFS unescape_string_for_display $_[0] -> $ret";
150
- return $ret;
151
- }
152
-
153
- sub escape_path_string {
154
- return $_[0];
155
-
156
- # used to be Gnome2::VFS->escape_path_string.
157
- my $ret = Gnome2::VFS->escape_path_string($_[0]);
158
- say "VFS escape_path_string $_[0] -> $ret";
159
- return $ret;
160
- }
161
 
162
  #--------------------------------------
163
 
@@ -249,6 +216,10 @@ require Shutter::Screenshot::Error;
249
  #upload classes
250
  require Shutter::Upload::FTP;
251
 
 
 
 
 
252
  #--------------------------------------
253
 
254
  my $sc = Shutter::App::Common->new(
 
122
 
123
  use English;
124
 
125
+ # escape_string, unescape_string, unescape_string_for_display and
126
+ # escape_path_string live in Shutter::App::Escape (required below, after
127
+ # the upload classes, once the module path is known)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
128
 
129
  #--------------------------------------
130
 
 
216
  #upload classes
217
  require Shutter::Upload::FTP;
218
 
219
+ #escape helpers
220
+ require Shutter::App::Escape;
221
+ Shutter::App::Escape->import(qw(escape_string unescape_string unescape_string_for_display escape_path_string));
222
+
223
  #--------------------------------------
224
 
225
  my $sc = Shutter::App::Common->new(
share/shutter/resources/modules/Shutter/App/Escape.pm ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ###################################################
2
+ #
3
+ # Copyright (C) 2008-2013 Mario Kemper <mario.kemper@gmail.com>
4
+ #
5
+ # This file is part of Shutter.
6
+ #
7
+ # Shutter is free software; you can redistribute it and/or modify
8
+ # it under the terms of the GNU General Public License as published by
9
+ # the Free Software Foundation; either version 3 of the License, or
10
+ # (at your option) any later version.
11
+ #
12
+ # Shutter is distributed in the hope that it will be useful,
13
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ # GNU General Public License for more details.
16
+ #
17
+ # You should have received a copy of the GNU General Public License
18
+ # along with Shutter; if not, write to the Free Software
19
+ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20
+ #
21
+ ###################################################
22
+
23
+ package Shutter::App::Escape;
24
+
25
+ #modules
26
+ #--------------------------------------
27
+ use utf8;
28
+ use strict;
29
+ use warnings;
30
+ use feature qw(say);
31
+
32
+ use Exporter qw(import);
33
+ our @EXPORT_OK = qw(escape_string unescape_string unescape_string_for_display escape_path_string);
34
+
35
+ ## no critic (ControlStructures::ProhibitUnreachableCode)
36
+ # The Gnome2::VFS branches below are kept verbatim from bin/shutter for
37
+ # reference; they are never reached.
38
+
39
+ sub escape_string {
40
+ return $_[0];
41
+
42
+ # used to be Gnome2::VFS->escape_string.
43
+ my $ret = Gnome2::VFS->escape_string($_[0]);
44
+ say "VFS escape_string $_[0] -> $ret";
45
+ return $ret;
46
+ }
47
+
48
+ sub unescape_string {
49
+ return $_[0];
50
+
51
+ # used to be Gnome2::VFS->unescape_string.
52
+ # at least, transform utf-8 to internal perl format for utf8
53
+ my $ret = Gnome2::VFS->unescape_string($_[0]);
54
+ say "VFS unescape_string $_[0] -> $ret";
55
+ return $ret;
56
+ }
57
+
58
+ sub unescape_string_for_display {
59
+ return $_[0];
60
+
61
+ # used to be Gnome2::VFS->unescape_string_for_display.
62
+ my $ret = Gnome2::VFS->unescape_string_for_display($_[0]);
63
+ say "VFS unescape_string_for_display $_[0] -> $ret";
64
+ return $ret;
65
+ }
66
+
67
+ sub escape_path_string {
68
+ return $_[0];
69
+
70
+ # used to be Gnome2::VFS->escape_path_string.
71
+ my $ret = Gnome2::VFS->escape_path_string($_[0]);
72
+ say "VFS escape_path_string $_[0] -> $ret";
73
+ return $ret;
74
+ }
75
+
76
+ ## use critic
77
+
78
+ 1;
t/Shutter/App/10_escape.t ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/perl
2
+ # Unit tests for Shutter::App::Escape (the former VFS escape helpers).
3
+
4
+ use 5.010;
5
+ use strict;
6
+ use warnings;
7
+ use utf8;
8
+
9
+ use Test::More;
10
+
11
+ my @subs = qw(escape_string unescape_string unescape_string_for_display escape_path_string);
12
+
13
+ require_ok('Shutter::App::Escape');
14
+ can_ok('Shutter::App::Escape', @subs);
15
+
16
+ my @inputs = ('plain', 'with space', 'file:///tmp/a%20b.png', '/tmp/ünïcødé/ß.png', q{}, '100%');
17
+
18
+ for my $name (@subs) {
19
+ my $code = Shutter::App::Escape->can($name);
20
+ for my $in (@inputs) {
21
+ is($code->($in), $in, "$name returns '$in' unchanged");
22
+ }
23
+ is($code->(undef), undef, "$name passes undef through");
24
+ }
25
+
26
+ Shutter::App::Escape->import(@subs);
27
+ ok(defined &main::unescape_string, 'import installs unescape_string into caller');
28
+ is(escape_path_string('/a b'), '/a b', 'imported escape_path_string works');
29
+
30
+ done_testing();