Fey/NamedObjectSet.pm

filter: Statementstmt 100% 51 / 51 Branchbran 100% 4 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 15 / 15 Podpod 100% 6 / 6 totaltotal 100% 76 / 76 CC 3 SCAR 2.1
CC
3
Cov
100%
objects
2.0
is_same_as
2.0
BEGIN
1.0
CRAP 1.2
« Fey/Literal/Function.pm ↑ Summary Fey/Column/Alias.pm »
1 package Fey::NamedObjectSet;
2  
3 27 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 27 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 27 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 27 our $VERSION = '0.44';
8  
9 27 ▶use List::AllUtils qw( all pairwise );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 27 ▶use Tie::IxHash;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 27 ▶use Fey::Types qw( HashRef Named );
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 27 ▶use Moose 2.1200;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 27 has '_set' => (
17 is => 'bare',
18 isa => 'Tie::IxHash',
19 handles => {
20 _get => 'FETCH',
21 _add => 'STORE',
22 _delete => 'Delete',
23 _all => 'Values',
24 _keys => 'Keys',
25 },
26 required => 1,
27 );
28  
29 883 ▶sub BUILDARGS {
Subroutine BUILDARGS: called CC=1 SCAR=0.0
Pod documented
30 883 my $class = shift;
31  
32 883 return { _set => Tie::IxHash->new( map { $_->name() => $_ } @_ ) };
33 }
34  
35 874 ▶sub add {
Subroutine add: called CC=1 SCAR=0.0
Pod documented
36 874 my $self = shift;
37  
38 874 $self->_add( map { $_->name() => $_ } @_ );
39  
40 874 return;
41 }
42  
43 9 ▶sub delete {
Subroutine delete: called CC=1 SCAR=0.0
Pod documented
44 9 my $self = shift;
45  
46 9 $self->_delete( map { $_->name() } @_ );
47  
48 9 return;
49 }
50  
51 2701 ▶sub object {
Subroutine object: called CC=1 SCAR=0.0
Pod documented
52 2701 my $self = shift;
53  
54 2701 return $self->_get(shift);
55 }
56  
57 55 ▶sub objects {
Subroutine objects: called CC=2 SCAR=6.9
Pod documented
58 55 my $self = shift;
59  
60 55 ▶ return $self->_all() unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 42 13 55
61  
62 13 return grep {defined} map { $self->_get($_) } @_;
63 }
64  
65 118 ▶sub is_same_as {
Subroutine is_same_as: called CC=2 SCAR=6.9
Pod documented
66 118 my $self = shift;
67 118 my $other = shift;
68  
69 118 my @self_names = sort $self->_keys();
70 118 my @other_names = sort $other->_keys();
71  
72 118 ▶ return 0 unless @self_names == @other_names;
Branch: 1 branch
BranchTrueFalseTotal
unless @self_names == @other_names 6 112 118
73  
74 112 ▶ return all {$_} pairwise { $a eq $b } @self_names, @other_names;
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
75 }
76  
77 27 __PACKAGE__->meta()->make_immutable();
78  
79 27 1;
80  
81 =head1 SYNOPSIS
82  
83 my $set = Fey::NamedObjectSet->new( $name_col, $size_col );
84  
85 =head1 DESCRIPTION
86  
87 This class represents a set of named objects, such as tables or
88 columns. You can look up objects in the set by name, or simply
89 retrieve all of the objects at once.
90  
91 It exists to simplify Fey's internals, since named sets of objects are
92 quite common in SQL.
93  
94 =head1 METHODS
95  
96 This class provides the following methods:
97  
98 =head2 Fey::NamedObjectSet->new(@objects)
99  
100 This method returns a new C<Fey::NamedObjectSet> object. Any objects
101 passed to this method are added to the set as it is created. Each
102 object passed must implement a C<name()> method, which is expected to
103 return a unique name for that object.
104  
105 =head2 $set->add(@objects)
106  
107 Adds one or more named objects to the set.
108  
109 =head2 $set->delete(@objects)
110  
111 This method accepts one or more objects and removes them from the set,
112 if they are part of it.
113  
114 =head2 $set->object($name)
115  
116 Given a name, this method returns the corresponding object.
117  
118 =head2 $set->objects(@names)
119  
120 When given a list of names as an argument, this method returns the
121 named objects in the order specified, if they exist in the set. If not
122 given any arguments it returns all of the objects in the set.
123  
124 =head2 $set->is_same_as($other_set)
125  
126 Given a C<Fey::NamedObjectSet>, this method indicates whether or not
127 the two sets are the same.
128  
129 =head1 BUGS
130  
131 See L<Fey> for details on how to report bugs.
132  
133 =cut
« Fey/Literal/Function.pm ↑ Summary Fey/Column/Alias.pm »