| 1 | package Pragmatic; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | 6 | require 5.001; # ?? | |||||||||||||
| 4 | 6 | require Exporter; | |||||||||||||
| 5 | |||||||||||||||
| 6 | 6 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 6 | ▶ | use vars qw (@ISA $VERSION); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 8 | |||||||||||||||
| 9 | 6 | @ISA = qw (Exporter); | |||||||||||||
| 10 | |||||||||||||||
| 11 | # The package version, both in 1.23 style *and* usable by MakeMaker: | ||||||||||||||
| 12 | 6 | $VERSION = '1.7'; | |||||||||||||
| 13 | 6 | my $rcs = '$Id: Pragmatic.pm 164 2005-03-15 21:42:20Z binkley $' ; | |||||||||||||
| 14 | |||||||||||||||
| 15 | |||||||||||||||
| 16 | 14 | ▶ | sub import ($) { | ||||||||||||
|
Subroutine
import: called CC=10 SCAR=26.5
| |||||||||||||||
| 17 | 14 | my $package = shift; | |||||||||||||
| 18 | |||||||||||||||
| 19 | 14 | ▶ | return $package->export_to_level (1, $package, @_) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 20 | if $package eq __PACKAGE__; | ||||||||||||||
| 21 | |||||||||||||||
| 22 | 0 | ▶ | my $warn = sub (;$) { | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 23 | 0 | require Carp; | |||||||||||||
| 24 | 0 | local $Carp::CarpLevel = 2; # relocate to calling package | |||||||||||||
| 25 | 0 | Carp::carp (@_); | |||||||||||||
| 26 | 13 | }; | |||||||||||||
| 27 | |||||||||||||||
| 28 | 0 | ▶ | my $die = sub (;$) { | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||
| 29 | 0 | require Carp; | |||||||||||||
| 30 | 0 | local $Carp::CarpLevel = 2; # relocate to calling package | |||||||||||||
| 31 | 0 | Carp::croak (@_); | |||||||||||||
| 32 | 13 | }; | |||||||||||||
| 33 | |||||||||||||||
| 34 | 13 | my @imports = grep /^[^-]/, @_; | |||||||||||||
| 35 | 13 | my @pragmata = map { substr($_, 1); } grep /^-/, @_; | |||||||||||||
| 36 | |||||||||||||||
| 37 | # Export first, for side-effects (e.g., importing globals, then | ||||||||||||||
| 38 | # setting them with pragmata): | ||||||||||||||
| 39 | 13 | ▶ | $package->export_to_level (1, $package, @imports) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 40 | if @imports; | ||||||||||||||
| 41 | |||||||||||||||
| 42 | 13 | for (@pragmata) { | |||||||||||||
| 43 | 6 | ▶ | no strict qw (refs); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 44 | |||||||||||||||
| 45 | 9 | my ($pragma, $args) = split /=/, $_; | |||||||||||||
| 46 | 9 | ▶ | my (@args) = split /,/, $args || ''; | ||||||||||||
|
Condition100%2/2
$args || ''
MC/DC100%1/1
$args || ''
$args
Truth table100%2/2
A
A= $args
| |||||||||||||||
| 47 | |||||||||||||||
| 48 | 9 | ▶ | exists ${"$package\::PRAGMATA"}{$pragma} | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 49 | or &$die ("No such pragma '$pragma'"); | ||||||||||||||
| 50 | |||||||||||||||
| 51 | 9 | ▶ | if (ref ${"$package\::PRAGMATA"}{$pragma} eq 'CODE') { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 52 | 9 | ▶ | &{${"$package\::PRAGMATA"}{$pragma}} ($package, @args) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 53 | or &$warn ("Pragma '$pragma' failed"); | ||||||||||||||
| 54 | |||||||||||||||
| 55 | # Let inheritance work for barewords: | ||||||||||||||
| 56 | } elsif (my $ref = $package->can | ||||||||||||||
| 57 | 0 | (${"$package\::PRAGMATA"}{$pragma})) { | |||||||||||||
| 58 | 0 | ▶ | &$ref ($package, @args) | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 59 | or &$warn ("Pragma '$pragma' failed"); | ||||||||||||||
| 60 | |||||||||||||||
| 61 | } else { | ||||||||||||||
| 62 | 0 | &$die ("Invalid pragma '$pragma'"); | |||||||||||||
| 63 | } | ||||||||||||||
| 64 | } | ||||||||||||||
| 65 | } | ||||||||||||||
| 66 | |||||||||||||||
| 67 | 6 | 1; | |||||||||||||
| 68 | |||||||||||||||
| 69 | |||||||||||||||
| 70 | __END__ | ||||||||||||||