• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ferki / Rex / 15240232617

28 Feb 2025 09:08AM UTC coverage: 50.961% (+10.2%) from 40.73%
15240232617

push

github

ferki
Use placeholders for template hints

10072 of 19764 relevant lines covered (50.96%)

101.57 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.64
/lib/Rex/Helper/Encode.pm
1
#
2
# (c) Jan Gehring <jan.gehring@gmail.com>
3
#
4

5
package Rex::Helper::Encode;
6

7
use v5.12.5;
35✔
8
use warnings;
35✔
9

10
our $VERSION = '9999.99.99_99'; # VERSION
11

12
require Exporter;
13
use base qw(Exporter);
35✔
14
use vars qw(@EXPORT);
35✔
15
@EXPORT = qw(func_to_json);
16

17
my %escapes;
18
for ( 0 .. 255 ) {
19
  $escapes{ chr($_) } = sprintf( "%%%02X", $_ );
20
}
21

22
sub url_encode {
23
  my ($txt) = @_;
1✔
24
  $txt =~ s/([^A-Za-z0-9_])/$escapes{$1}/g;
1✔
25
  return $txt;
1✔
26
}
27

28
sub url_decode {
29
  my ($txt) = @_;
×
30
  $txt =~ s/%([0-9A-Fa-f]{2})/chr(hex($1))/eg;
×
31
  return $txt;
×
32
}
33

34
sub func_to_json {
35

36
  return q|
×
37
  sub to_json {
38
    my ($ref) = @_;
39

40
    my $s = "";
41

42
    if(ref $ref eq "ARRAY") {
43
      $s .= "[";
44
      for my $itm (@{ $ref }) {
45
        if(substr($s, -1) ne "[") {
46
          $s .= ",";
47
        }
48
        $s .= to_json($itm);
49
      }
50
      return $s . "]";
51
    }
52
    elsif(ref $ref eq "HASH") {
53
      $s .= "{";
54
      for my $key (keys %{ $ref }) {
55
        if(substr($s, -1) ne "{") {
56
          $s .= ",";
57
        }
58
        $s .= "\"$key\": " . to_json($ref->{$key});
59
      }
60
      return $s . "}";
61
    }
62
    else {
63
      if($ref =~ /^0\d+/) {
64
        return "\"$ref\"";
65
      }
66
      elsif($ref =~ /^\d+$/) {
67
        return $ref;
68
      }
69
      else {
70
        $ref =~ s/'/\\\'/g;
71
        return "\"$ref\"";
72
      }
73
    }
74
  }
75

76
  |;
77

78
}
79

80
1;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc