Sticker/Derive/Title.pm

filter: Statementstmt 48.2% 14 / 29 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 4 / 7 Podpod 100% 3 / 3 totaltotal 51.2% 21 / 41 CC 2 SCAR 9.2
CC
2
Cov
45%
derive
6.0
whoami
2.0
order
2.0
CRAP 2.5
« Sticker/Derive.pm ↑ Summary Sticker.pm »
1 package File::Sticker::Derive::Title;
2 1 $File::Sticker::Derive::Title::VERSION = '4.9';
3 =head1 NAME
4  
5 File::Sticker::Derive::Title - derive values from existing meta-data
6  
7 =head1 VERSION
8  
9 version 4.9
10  
11 =head1 SYNOPSIS
12  
13 use File::Sticker::Derive::Title;
14  
15 my $deriver = File::Sticker::Derive::Title->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 This is the Title plugin, which derives a "title" from the file name
23 if there isn't already a title.
24  
25 =cut
26  
27 1 ▶use common::sense;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use Path::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 1 ▶use String::CamelCase qw(wordsplit);
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 1 ▶use parent qw(File::Sticker::Derive);
Subroutine BEGIN: called CC=1 SCAR=0.0
32  
33 =head1 DEBUGGING
34  
35 =head2 whoami
36  
37 Used for debugging info
38  
39 =cut
40 0 ▶sub whoami { ( caller(1) )[3] }
Subroutine whoami: not called CC=1 SCAR=6.9
Pod documented
41  
42 =head1 METHODS
43  
44 =head2 order
45  
46 The order of this deriver, ranging from 0 to 99.
47 This makes sure that the deriver is applied in order;
48 useful because a later deriver may depend on data created
49 by an earlier deriver.
50  
51 =cut
52  
53 0 ▶sub order {
Subroutine order: not called CC=1 SCAR=6.9
Pod documented
54 0 return 90;
55 } # order
56  
57 =head2 derive
58  
59 Derive common values from the existing meta-data.
60 This UPDATES the passed-in meta hash.
61  
62 $deriver->derive(filename=>$filename, meta=>$meta, overwrite=>\%overwrite);
63  
64 =cut
65  
66 0 ▶sub derive {
Subroutine derive: not called CC=2 SCAR=17.9
Pod documented
67 0 my $self = shift;
68 0 my %args = @_;
69 0 ▶ say STDERR whoami() if $self->{verbose} > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 2 0 0 0
70  
71 0 my $filename = $args{filename};
72 0 my $meta = $args{meta};
73  
74 # title
75 0 my $fp = path($filename);
76 0 my $id_name = $fp->basename(qr/\.\w+/);
77 0 my @words = wordsplit($id_name);
78 0 my $title = join(' ', @words);
79 0 $title =~ s/(\w+)/\u\L$1/g; # title case
80 0 $title =~ s/(\d+)$/ $1/; # trailing numbers
81 0 $self->_set_field(%args, meta=>$meta, field=>'title', value=>$title);
82  
83 0 return $meta;
84 } # derive
85  
86 =head1 BUGS
87  
88 Please report any bugs or feature requests to the author.
89  
90 =cut
91  
92 1 1; # End of File::Sticker::Derive::Title
93 __END__
« Sticker/Derive.pm ↑ Summary Sticker.pm »