blib/lib/SQL/Translator/Schema/Role/Extra.pm

filter: Statementstmt 100% 24 / 24 Branchbran 100% 12 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 100% 41 / 41 SCAR 19.5
CC
7
Cov
100%
__ANON__
6.0
remove_extra
2.0
BEGIN
1.0
CRAP 7.0
« blib/lib/SQL/Translator/Generator/Role/Quote.pm ↑ Summary blib/lib/SQL/Translator/Producer/Latex.pm »
1 package SQL::Translator::Schema::Role::Extra;
2  
3 =head1 NAME
4  
5 SQL::Translator::Schema::Role::Extra - "extra" attribute for schema classes
6  
7 =head1 SYNOPSIS
8  
9 package Foo;
10 use Moo;
11 with qw(SQL::Translator::Schema::Role::Extra);
12  
13 =head1 DESCRIPTION
14  
15 This role provides methods to set and get a hashref of extra attributes
16 for schema objects.
17  
18 =cut
19  
20 74 ▶use Moo::Role;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 74 ▶use Sub::Quote qw(quote_sub);
Subroutine BEGIN: called CC=1 SCAR=0.0
22  
23  
24 =head1 METHODS
25  
26 =head2 extra
27  
28 Get or set the objects "extra" attributes (e.g., "ZEROFILL" for MySQL fields).
29 Call with no args to get all the extra data.
30 Call with a single name arg to get the value of the named extra attribute,
31 returned as a scalar. Call with a hash or hashref to set extra attributes.
32 Returns a hash or a hashref.
33  
34 $field->extra( qualifier => 'ZEROFILL' );
35  
36 $qualifier = $field->extra('qualifier');
37  
38 %extra = $field->extra;
39 $extra = $field->extra;
40  
41 =cut
42  
43 74 has extra => ( is => 'rwp', default => quote_sub(q{ +{} }) );
44  
45 around extra => sub {
46 4586 ▶ my ($orig, $self) = (shift, shift);
Subroutine __ANON__: called CC=6 SCAR=17.9
47  
48 4586 ▶ @_ = %{$_[0]} if ref $_[0] eq "HASH";
Branch: 1 branch
BranchTrueFalseTotal
if ref $_[0] eq "HASH" 1 4585 4586
49 4586 my $extra = $self->$orig;
50  
51 4586 ▶ if (@_==1) {
Branch: 2 branches
BranchTrueFalseTotal
if (@_ == 1) { } 266 4320 4586
elsif (@_) { } 41 4279 4320
52 266 return $extra->{$_[0]};
53 }
54 elsif (@_) {
55 41 my %args = @_;
56 41 ▶ while ( my ( $key, $value ) = each %args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (() = each %args) 75 41 116
57 75 $extra->{$key} = $value;
58 }
59 }
60  
61 4320 ▶ return wantarray ? %$extra : $extra;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 904 3416 4320
62 74 };
63  
64 =head2 remove_extra
65  
66 L</extra> can only be used to get or set "extra" attributes but not to
67 remove some. Call with no args to remove all extra attributes that
68 have been set before. Call with a list of key names to remove
69 certain extra attributes only.
70  
71 # remove all extra attributes
72 $field->remove_extra();
73  
74 # remove timezone and locale attributes only
75 $field->remove_extra(qw/timezone locale/);
76  
77 =cut
78  
79 sub remove_extra {
80 4 ▶ my ( $self, @keys ) = @_;
Subroutine remove_extra: called CC=2 SCAR=6.9
Pod documented
81 4 ▶ unless (@keys) {
Branch: 1 branch
BranchTrueFalseTotal
if (@keys) { } 2 2 4
82 2 $self->_set_extra({});
83 }
84 else {
85 2 delete @{$self->extra}{@keys};
86 }
87 }
88  
89 74 1;
« blib/lib/SQL/Translator/Generator/Role/Quote.pm ↑ Summary blib/lib/SQL/Translator/Producer/Latex.pm »