|
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 | |
|---|
| 4 | package Perlbal::Util; |
|---|
| 5 | use strict; |
|---|
| 6 | use warnings; |
|---|
| 7 | no warnings qw(deprecated); |
|---|
| 8 | |
|---|
| 9 | sub 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 | |
|---|
| 17 | Safely re-bless a locked (use fields) hash into another package. Note |
|---|
| 18 | that for our convenience elsewhere the set of allowable keys for the |
|---|
| 19 | re-blessed hash will be the union of the keys allowed by its old package |
|---|
| 20 | and those allowed for the package into which it is blessed. |
|---|
| 21 | |
|---|
| 22 | =cut |
|---|
| 23 | |
|---|
| 24 | BEGIN { |
|---|
| 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 | |
|---|
| 47 | 1; |
|---|
| 48 | |
|---|
| 49 | # Local Variables: |
|---|
| 50 | # mode: perl |
|---|
| 51 | # c-basic-indent: 4 |
|---|
| 52 | # indent-tabs-mode: nil |
|---|
| 53 | # End: |
|---|