| 1 | package Petal::Utils::Base; | ||||||||||||||
| 2 | |||||||||||||||
| 3 | #rename: package Petal::Plugin; ? | ||||||||||||||
| 4 | |||||||||||||||
| 5 | 15 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 15 | ▶ | use warnings::register; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 15 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | |||||||||||||||
| 10 | 15 | our $VERSION = ((require Petal::Utils), $Petal::Utils::VERSION)[1]; | |||||||||||||
| 11 | 15 | our $REVISION = (split(/ /, ' $Revision: 1.5 $ '))[2]; | |||||||||||||
| 12 | |||||||||||||||
| 13 | ## Define the enclosed packages inside the Petal Modifiers hash | ||||||||||||||
| 14 | 75 | ▶ | sub install { | ||||||||||||
|
Subroutine
install: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 15 | 75 | my $class = shift; | |||||||||||||
| 16 | |||||||||||||||
| 17 | 75 | foreach my $name ($class->name, $class->aliases) { | |||||||||||||
| 18 | 90 | $Petal::Hash::MODIFIERS->{"$name:"} = $class; | |||||||||||||
| 19 | } | ||||||||||||||
| 20 | |||||||||||||||
| 21 | 75 | return $class; | |||||||||||||
| 22 | } | ||||||||||||||
| 23 | |||||||||||||||
| 24 | 0 | ▶ | sub process { | ||||||||||||
|
Subroutine
process: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 25 | 0 | my $class = shift; | |||||||||||||
| 26 | 0 | confess( "$class does not override process()" ); | |||||||||||||
| 27 | } | ||||||||||||||
| 28 | |||||||||||||||
| 29 | 0 | ▶ | sub name { | ||||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 30 | 0 | my $class = shift; | |||||||||||||
| 31 | 0 | confess( "$class does not override name()" ); | |||||||||||||
| 32 | } | ||||||||||||||
| 33 | |||||||||||||||
| 34 | 0 | ▶ | sub aliases { | ||||||||||||
|
Subroutine
aliases: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 35 | 0 | my $class = shift; | |||||||||||||
| 36 | 0 | confess( "$class does not override aliases()" ); | |||||||||||||
| 37 | } | ||||||||||||||
| 38 | |||||||||||||||
| 39 | 9 | ▶ | sub split_first_arg { | ||||||||||||
|
Subroutine
split_first_arg: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 40 | 9 | my $class = shift; | |||||||||||||
| 41 | 9 | my $args = shift; | |||||||||||||
| 42 | # don't use split(/\s/,...) as we might kill an expression that way | ||||||||||||||
| 43 | 9 | return ($args =~ /\A(.+?)\s+(.*)\z/); | |||||||||||||
| 44 | } | ||||||||||||||
| 45 | |||||||||||||||
| 46 | # Return a list of all arguments as an array - does not perform expansion on | ||||||||||||||
| 47 | # embedded modifiers | ||||||||||||||
| 48 | 40 | ▶ | sub split_args { | ||||||||||||
|
Subroutine
split_args: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||
| 49 | 40 | my $class = shift; | |||||||||||||
| 50 | 40 | my ($args) = @_; | |||||||||||||
| 51 | # W. Smith's regex | ||||||||||||||
| 52 | 40 | return ($args =~ /('[^']+'|\S+)/g); | |||||||||||||
| 53 | } | ||||||||||||||
| 54 | |||||||||||||||
| 55 | # Returns an argument from the data hash as a string/object or as a plaintext | ||||||||||||||
| 56 | # if arg is surrounded by single quotes or a number (decimal points OK) | ||||||||||||||
| 57 | # Arguments: | ||||||||||||||
| 58 | # $hash - reference to the Petal data hash | ||||||||||||||
| 59 | # $arg - the argument | ||||||||||||||
| 60 | 69 | ▶ | sub fetch_arg { | ||||||||||||
|
Subroutine
fetch_arg: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||
| 61 | 69 | my $class = shift; | |||||||||||||
| 62 | 69 | my ($hash, $arg) = @_; | |||||||||||||
| 63 | |||||||||||||||
| 64 | 69 | ▶ | return undef unless defined($arg); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 65 | 64 | ▶ | if($arg =~ /\'/) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 66 | 22 | $arg =~ s/\'//g; | |||||||||||||
| 67 | 22 | return $arg; | |||||||||||||
| 68 | } | ||||||||||||||
| 69 | elsif($arg =~ /^[0-9.]+$/) { | ||||||||||||||
| 70 | 13 | return $arg; | |||||||||||||
| 71 | } | ||||||||||||||
| 72 | else { | ||||||||||||||
| 73 | #warn "Returning hash key for $arg"; | ||||||||||||||
| 74 | 29 | return $hash->fetch($arg); | |||||||||||||
| 75 | } | ||||||||||||||
| 76 | } | ||||||||||||||
| 77 | |||||||||||||||
| 78 | |||||||||||||||
| 79 | |||||||||||||||
| 80 | |||||||||||||||
| 81 | 15 | 1; | |||||||||||||
| 82 | |||||||||||||||