Object/Policy.pm

filter: Statementstmt 100% 38 / 38 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 100% 1 / 1 totaltotal 100% 52 / 52 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« ORM/Types.pm ↑ Summary
1 package Fey::Object::Policy;
2 {
3 10 $Fey::Object::Policy::VERSION = '0.46';
4 }
5  
6 10 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 10 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 10 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 10 ▶use Fey::ORM::Types qw( ArrayRef CodeRef HashRef );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 10 ▶use List::Util qw( first );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 10 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 10 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 10 ▶use MooseX::SemiAffordanceAccessor;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 has '_transforms' => (
18 traits => ['Array'],
19 is => 'ro',
20 isa => ArrayRef[HashRef],
21 54 ▶ default => sub { [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
22 10 init_arg => undef,
23 handles => {
24 add_transform => 'push',
25 transforms => 'elements',
26 },
27 );
28  
29 10 has 'has_one_namer' => (
30 is => 'rw',
31 isa => CodeRef,
32 default => \&_dumb_namer,
33 required => 1,
34 );
35  
36 10 has 'has_many_namer' => (
37 is => 'rw',
38 isa => CodeRef,
39 default => \&_dumb_namer,
40 required => 1,
41 );
42  
43 sub transform_for_column {
44 79 ▶ my $self = shift;
Subroutine transform_for_column: called CC=1 SCAR=0.0
Pod documented
45 79 my $column = shift;
46  
47 79 ▶ return first { $_->{matching}->($column) } $self->transforms();
Subroutine __ANON__: called CC=1 SCAR=0.0
48 }
49  
50 sub _dumb_namer {
51 4 ▶ return sub { lc $_[0]->name() };
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine _dumb_namer: called CC=1 SCAR=0.0
52 }
53  
54 10 __PACKAGE__->meta()->make_immutable();
55  
56 10 1;
57  
58 # ABSTRACT: An object representing a specific policy
59  
60 __END__
61  
62 =pod
63  
64 =head1 NAME
65  
66 Fey::Object::Policy - An object representing a specific policy
67  
68 =head1 VERSION
69  
70 version 0.46
71  
72 =head1 DESCRIPTION
73  
74 This class provides the non-sugar half of L<Fey::ORM::Policy>. It's
75 probably not interesting unless you're interested in the guts of how
76 L<Fey::ORM> works.
77  
78 =head1 METHODS
79  
80 This class accepts the following methods:
81  
82 =head2 $policy->add_transform( matching => sub { ... }, inflate => sub { ... }, deflate => sub { ... } )
83  
84 Stores a transform as declared in L<Fey::ORM::Policy>
85  
86 =head2 $policy->transform_for_column($column)
87  
88 Given a L<Fey::Column>, returns the first transform (as a hash
89 reference) for which the C<matching> sub returns true.
90  
91 =head2 $policy->transforms()
92  
93 Returns all of the transforms for the policy.
94  
95 =head2 $policy->has_one_namer()
96  
97 Returns the naming sub for C<has_one()> methods. Defaults to:
98  
99 sub { lc $_[0]->name() }
100  
101 =head2 $policy->set_has_one_namer($sub)
102  
103 Sets the naming sub for C<has_one()> methods.
104  
105 =head2 $policy->has_many_namer()
106  
107 Returns the naming sub for C<has_many()> methods. Defaults to:
108  
109 sub { lc $_[0]->name() }
110  
111 =head2 $policy->set_has_many_namer($sub)
112  
113 Sets the naming sub for C<has_many()> methods.
114  
115 =head1 AUTHOR
116  
117 Dave Rolsky <autarch@urth.org>
118  
119 =head1 COPYRIGHT AND LICENSE
120  
121 This software is copyright (c) 2011 by Dave Rolsky.
122  
123 This is free software; you can redistribute it and/or modify it under
124 the same terms as the Perl 5 programming language system itself.
125  
126 =cut
« ORM/Types.pm ↑ Summary