root/trunk/lib/Perlbal/Util.pm

Revision 802, 1.2 kB (checked in by ask, 12 months ago)

support filenames with +'s in webserver mode (Jordi Funollet).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1# misc util functions
2#
3
4package Perlbal::Util;
5use strict;
6use warnings;
7no  warnings qw(deprecated);
8
9sub durl {
10    my ($txt) = @_;
11    $txt =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
12    return $txt;
13}
14
15=head2 C< rebless >
16
17Safely re-bless a locked (use fields) hash into another package. Note
18that for our convenience elsewhere the set of allowable keys for the
19re-blessed hash will be the union of the keys allowed by its old package
20and those allowed for the package into which it is blessed.
21
22=cut
23
24BEGIN {
25    if ($] >= 5.010) {
26        eval q{
27            use Hash::Util qw(legal_ref_keys unlock_ref_keys lock_ref_keys)
28        };
29        *rebless = sub {
30            my ($obj, $pkg) = @_;
31            my @keys = legal_ref_keys($obj);
32            unlock_ref_keys($obj);
33            bless $obj, $pkg;
34            lock_ref_keys($obj, @keys,
35                          legal_ref_keys(fields::new($pkg)));
36            return $obj;
37        };
38    }
39    else {
40        *rebless = sub {
41            my ($obj, $pkg) = @_;
42            return bless $obj, $pkg;
43        };
44    }
45}
46
471;
48
49# Local Variables:
50# mode: perl
51# c-basic-indent: 4
52# indent-tabs-mode: nil
53# End:
Note: See TracBrowser for help on using the browser.