| 1 | package File::Sticker::Derive; | ||||||||||||||||||||
| 2 | 3 | $File::Sticker::Derive::VERSION = '4.8'; | |||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | File::Sticker::Derive - derive values from existing meta-data | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | =head1 VERSION | ||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | version 4.8 | ||||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | use File::Sticker::Derive; | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | my $deriver = File::Sticker::Derive->new(%args); | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | my $derived_meta = $deriver->derive(filename=>$filename,meta=>$meta); | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | =head1 DESCRIPTION | ||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | This will derive values from existing meta-data. | ||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | This is a plug-in, different plug-ins will do different derivations. | ||||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | =cut | ||||||||||||||||||||
| 26 | |||||||||||||||||||||
| 27 | 3 | ▶ | use common::sense; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | =head1 DEBUGGING | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | =head2 whoami | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | Used for debugging info | ||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | =cut | ||||||||||||||||||||
| 36 | 0 | ▶ | sub whoami { ( caller(1) )[3] } | ||||||||||||||||||
|
Subroutine
whoami: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | =head1 METHODS | ||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | =head2 new | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | Create a new object, setting global values for the object. | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | my $obj = File::Sticker::Derive->new(); | ||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | =cut | ||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | sub new { | ||||||||||||||||||||
| 49 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 50 | 0 | my %parameters = (@_); | |||||||||||||||||||
| 51 | 0 | ▶ | my $self = bless ({%parameters}, ref ($class) || $class); | ||||||||||||||||||
|
Condition0%0/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table0%0/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||
| 52 | |||||||||||||||||||||
| 53 | 0 | return ($self); | |||||||||||||||||||
| 54 | } # new | ||||||||||||||||||||
| 55 | |||||||||||||||||||||
| 56 | =head2 init | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | Initialize the object. | ||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | $deriver->init(%args); | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | =cut | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | sub init { | ||||||||||||||||||||
| 65 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
init: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 66 | 0 | my %parameters = @_; | |||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | 0 | foreach my $key (keys %parameters) | |||||||||||||||||||
| 69 | { | ||||||||||||||||||||
| 70 | 0 | $self->{$key} = $parameters{$key}; | |||||||||||||||||||
| 71 | } | ||||||||||||||||||||
| 72 | } # init | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | =head2 name | ||||||||||||||||||||
| 75 | |||||||||||||||||||||
| 76 | The name of the deriver; this is basically the last component | ||||||||||||||||||||
| 77 | of the module name. This works as either a class function or a method. | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | $name = $self->name(); | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | $name = File::Sticker::Derive::name($class); | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | =cut | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | sub name { | ||||||||||||||||||||
| 86 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
name: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | 0 | ▶ | my $fullname = (ref ($class) ? ref ($class) : $class); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 89 | |||||||||||||||||||||
| 90 | 0 | my @bits = split('::', $fullname); | |||||||||||||||||||
| 91 | 0 | return pop @bits; | |||||||||||||||||||
| 92 | } # name | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | =head2 order | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | The order of this deriver, ranging from 0 to 99. | ||||||||||||||||||||
| 97 | This makes sure that the deriver is applied in order; | ||||||||||||||||||||
| 98 | useful because a later deriver may depend on data created | ||||||||||||||||||||
| 99 | by an earlier deriver. | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | This must be overridden by the specific deriver class. | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | =cut | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | sub order { | ||||||||||||||||||||
| 106 | 0 | ▶ | return 50; | ||||||||||||||||||
|
Subroutine
order: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 107 | } # order | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | =head2 derive | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | Derive common values from the existing meta-data. | ||||||||||||||||||||
| 112 | This is expected to return a new hash. | ||||||||||||||||||||
| 113 | DOES NOT alter the passed-in data. | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | This must be overridden by the specific deriver class. | ||||||||||||||||||||
| 116 | |||||||||||||||||||||
| 117 | my $newmeta = $deriver->derive(filename=>$filename, meta=>$meta); | ||||||||||||||||||||
| 118 | |||||||||||||||||||||
| 119 | =cut | ||||||||||||||||||||
| 120 | |||||||||||||||||||||
| 121 | sub derive { | ||||||||||||||||||||
| 122 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
derive: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 123 | 0 | my %args = @_; | |||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | 0 | my $filename = $args{filename}; | |||||||||||||||||||
| 126 | 0 | my $meta = $args{meta}; | |||||||||||||||||||
| 127 | } # derive | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | =head1 Helper Functions | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | Private interface. | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | |||||||||||||||||||||
| 134 | =head1 BUGS | ||||||||||||||||||||
| 135 | |||||||||||||||||||||
| 136 | Please report any bugs or feature requests to the author. | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | =cut | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | 3 | 1; # End of File::Sticker::Derive | |||||||||||||||||||
| 141 | __END__ | ||||||||||||||||||||