| 1 | # misc util functions | ||||||||||
| 2 | # | ||||||||||
| 3 | |||||||||||
| 4 | package Perlbal::Util; | ||||||||||
| 5 | 22 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 22 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | 22 | ▶ | no warnings qw(deprecated); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | 55 | ▶ | sub durl { | ||||||||
|
Subroutine
durl: called CC=1 SCAR=0.2
Pod
undocumented
| |||||||||||
| 10 | 55 | my ($txt) = @_; | |||||||||
| 11 | 0 | $txt =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg; | |||||||||
| 12 | 55 | 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 | 22 | ▶ | BEGIN { | ||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.2
| |||||||||||
| 25 | 22 | ▶ | if ($] >= 5.010) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | 22 | ▶ | eval q{ | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | use Hash::Util qw(legal_ref_keys unlock_ref_keys lock_ref_keys) | ||||||||||
| 28 | }; | ||||||||||
| 29 | 150 | ▶ | *rebless = sub { | ||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||
| 30 | 150 | my ($obj, $pkg) = @_; | |||||||||
| 31 | 150 | my @keys = legal_ref_keys($obj); | |||||||||
| 32 | 150 | unlock_ref_keys($obj); | |||||||||
| 33 | 150 | bless $obj, $pkg; | |||||||||
| 34 | 150 | lock_ref_keys($obj, @keys, | |||||||||
| 35 | legal_ref_keys(fields::new($pkg))); | ||||||||||
| 36 | 150 | return $obj; | |||||||||
| 37 | 22 | }; | |||||||||
| 38 | } | ||||||||||
| 39 | else { | ||||||||||
| 40 | 0 | ▶ | *rebless = sub { | ||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||
| 41 | 0 | my ($obj, $pkg) = @_; | |||||||||
| 42 | 0 | return bless $obj, $pkg; | |||||||||
| 43 | 0 | }; | |||||||||
| 44 | } | ||||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 22 | 1; | |||||||||
| 48 | |||||||||||
| 49 | # Local Variables: | ||||||||||
| 50 | # mode: perl | ||||||||||
| 51 | # c-basic-indent: 4 | ||||||||||
| 52 | # indent-tabs-mode: nil | ||||||||||
| 53 | # End: | ||||||||||