blib/lib/File/Sticker/Derive/Title.pm

filter: Statementstmt 46.6% 14 / 30 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 4 / 7 Podpod 100% 3 / 3 totaltotal 50.0% 21 / 42 CC 2 SCAR 9.2
CC
2
Cov
44%
derive
6.0
whoami
2.0
order
2.0
CRAP 2.5
« Build ↑ Summary blib/lib/File/Sticker.pm »
1 package File::Sticker::Derive::Title;
2 1 $File::Sticker::Derive::Title::VERSION = '4.8';
3 =head1 NAME
4  
5 File::Sticker::Derive::Title - 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::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 sub order {
54 0 ▶ return 90;
Subroutine order: not called CC=1 SCAR=6.9
Pod documented
55 } # order
56  
57 =head2 derive
58  
59 Derive common values from the existing meta-data.
60 This is expected to return a new hash.
61 DOES NOT alter the passed-in data.
62  
63 $deriver->derive(filename=>$filename, meta=>$meta);
64  
65 =cut
66  
67 sub derive {
68 0 ▶ my $self = shift;
Subroutine derive: not called CC=2 SCAR=17.9
Pod documented
69 0 my %args = @_;
70 0 ▶ say STDERR whoami() if $self->{verbose} > 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"verbose"} > 2 0 0 0
71  
72 0 my $filename = $args{filename};
73 0 my $oldmeta = $args{meta};
74  
75 # title
76 0 my $newmeta = {};
77 0 my $fp = path($filename);
78 0 my $id_name = $fp->basename(qr/\.\w+/);
79 0 my @words = wordsplit($id_name);
80 0 my $title = join(' ', @words);
81 0 $title =~ s/(\w+)/\u\L$1/g; # title case
82 0 $title =~ s/(\d+)$/ $1/; # trailing numbers
83 0 $newmeta->{title} = $title;
84  
85 0 return $newmeta;
86 } # derive
87  
88 =head1 BUGS
89  
90 Please report any bugs or feature requests to the author.
91  
92 =cut
93  
94 1 1; # End of File::Sticker::Derive::Title
95 __END__
« Build ↑ Summary blib/lib/File/Sticker.pm »