| 1 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | package Package::Reaper; | ||||||||||
| 4 | { | ||||||||||
| 5 | 1 | $Package::Reaper::VERSION = '1.106'; | |||||||||
| 6 | } | ||||||||||
| 7 | 1 | ▶ | use 5.008; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | # ABSTRACT: pseudo-garbage-collection for packages | ||||||||||
| 9 | |||||||||||
| 10 | 1 | ▶ | use Carp (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 1 | ▶ | use Symbol (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | 5 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 15 | 5 | my ($class, $package) = @_; | |||||||||
| 16 | |||||||||||
| 17 | # Do I care about checking $package with _CLASS and/or exists_package? | ||||||||||
| 18 | # Probably not, for now. -- rjbs, 2006-06-05 | ||||||||||
| 19 | 5 | my $self = [ $package, 1 ]; | |||||||||
| 20 | 5 | bless $self => $class; | |||||||||
| 21 | } | ||||||||||
| 22 | |||||||||||
| 23 | |||||||||||
| 24 | 6 | ▶ | sub package { | ||||||||
|
Subroutine
package: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 25 | 6 | my $self = shift; | |||||||||
| 26 | 6 | ▶ | Carp::croak "a reaper's package may not be altered" if @_; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 5 | return $self->[0]; | |||||||||
| 28 | } | ||||||||||
| 29 | |||||||||||
| 30 | |||||||||||
| 31 | 5 | ▶ | sub is_armed { | ||||||||
|
Subroutine
is_armed: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 32 | 5 | my $self = shift; | |||||||||
| 33 | 5 | return $self->[1] == 1; | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | |||||||||||
| 37 | 2 | ▶ | sub disarm { $_[0]->[1] = 0 } | ||||||||
|
Subroutine
disarm: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 38 | |||||||||||
| 39 | |||||||||||
| 40 | 1 | ▶ | sub arm { $_[0]->[1] = 1 } | ||||||||
|
Subroutine
arm: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 41 | |||||||||||
| 42 | 5 | ▶ | sub DESTROY { | ||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=6.9
| |||||||||||
| 43 | 5 | my ($self) = @_; | |||||||||
| 44 | |||||||||||
| 45 | 5 | ▶ | return unless $self->is_armed; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | |||||||||||
| 47 | 4 | my $package = $self->package; | |||||||||
| 48 | |||||||||||
| 49 | 4 | Symbol::delete_package($package); | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 1 | "You might be a king or a little street sweeper, but sooner or later you dance | |||||||||
| 53 | with Package:Reaper."; | ||||||||||
| 54 | |||||||||||
| 55 | __END__ | ||||||||||