| 1 | package Acme::Tie::Formatted; | ||||||||||||||||||||||||||||
| 2 | 8 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 8 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 8 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 8 | our $VERSION = '0.06'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 8 | my $first_char = qr/[_a-zA-Z]/; | |||||||||||||||||||||||||||
| 9 | 8 | my $next_char = qr/[_a-zA-Z0-9]/; | |||||||||||||||||||||||||||
| 10 | 8 | my $ok_name = qr/^$first_char($next_char)*$/; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 8 | our %format; | |||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 7 | ▶ | sub import { | ||||||||||||||||||||||||||
|
Subroutine
import: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 15 | 7 | $DB::single=1; | |||||||||||||||||||||||||||
| 16 | 7 | my ($class, $arg) = @_; | |||||||||||||||||||||||||||
| 17 | 7 | my $hash_name = "format"; | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 7 | ▶ | if (defined $arg and $arg =~ /$ok_name/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $arg and $arg =~ /$ok_name/
MC/DC50%1/2
defined $arg and $arg =~ /$ok_name/
defined $arg
$arg =~ /$ok_name/
Truth table66%2/3
A and B
A= defined $argB= $arg =~ /$ok_name/
| |||||||||||||||||||||||||||||
| 20 | 1 | $hash_name = $arg; | |||||||||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | { | ||||||||||||||||||||||||||||
| 24 | 8 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 25 | 7 | *{"main::$hash_name"} = \%format; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | # Connect the magic to the hash. | ||||||||||||||||||||||||||||
| 29 | 7 | tie %format, 'Acme::Tie::Formatted'; | |||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 7 | ▶ | sub TIEHASH { | ||||||||||||||||||||||||||
|
Subroutine
TIEHASH: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 7 | my $class = shift; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # Someplace to hang our hat. | ||||||||||||||||||||||||||||
| 37 | 7 | bless \my($self), $class; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 5 | ▶ | sub FETCH { | ||||||||||||||||||||||||||
|
Subroutine
FETCH: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||
| 41 | 5 | my ($self, $key) = @_; | |||||||||||||||||||||||||||
| 42 | 5 | ▶ | return '' unless $key; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | 4 | my @args = split $;, $key, -1; | |||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | # Return a null string if nothing was passed in. | ||||||||||||||||||||||||||||
| 47 | 4 | ▶ | return '' unless @args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 4 | my $format = pop @args; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | # Return a null string if there were no arguments | ||||||||||||||||||||||||||||
| 52 | # to be formatted. | ||||||||||||||||||||||||||||
| 53 | 4 | ▶ | return '' unless @args; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | # Format arguments and return. | ||||||||||||||||||||||||||||
| 56 | 4 | local $_; | |||||||||||||||||||||||||||
| 57 | 4 | return join($", map { sprintf($format, $_) } @args); | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | # Stolen directly from Tie::Comma. | ||||||||||||||||||||||||||||
| 61 | # Invalidate all other hash access. | ||||||||||||||||||||||||||||
| 62 | 8 | ▶ | use subs qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 63 | 8 | STORE EXISTS CLEAR FIRSTKEY NEXTKEY ); | |||||||||||||||||||||||||||
| 64 | *STORE = *EXISTS = *CLEAR = *FIRSTKEY = *NEXTKEY = | ||||||||||||||||||||||||||||
| 65 | 1 | ▶ | sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 66 | 1 | croak "You can only use %format by accessing it"; | |||||||||||||||||||||||||||
| 67 | 8 | }; | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 8 | 1; # Magic true value required at end of module | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||||||||