| 1 | ###################################################################### | ||||||||||
| 2 | # Copyright (c)2010-2011, David L. Armstrong. | ||||||||||
| 3 | # | ||||||||||
| 4 | # P4:OO::_Set.pm | ||||||||||
| 5 | # | ||||||||||
| 6 | # See COPYRIGHT AND LICENSE section in pod text below for usage | ||||||||||
| 7 | # and distribution rights. | ||||||||||
| 8 | # | ||||||||||
| 9 | ###################################################################### | ||||||||||
| 10 | |||||||||||
| 11 | =head1 NAME | ||||||||||
| 12 | |||||||||||
| 13 | =head1 SYNOPSIS | ||||||||||
| 14 | |||||||||||
| 15 | =head1 DESCRIPTION | ||||||||||
| 16 | |||||||||||
| 17 | =cut | ||||||||||
| 18 | |||||||||||
| 19 | |||||||||||
| 20 | ###################################################################### | ||||||||||
| 21 | # Package Initialization | ||||||||||
| 22 | # | ||||||||||
| 23 | package P4::OO::_Set; | ||||||||||
| 24 | 12 | our $VERSION = '0.00_02'; | |||||||||
| 25 | 12 | ▶ | use base 'P4::OO'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | 12 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 27 | |||||||||||
| 28 | |||||||||||
| 29 | ###################################################################### | ||||||||||
| 30 | # Globals | ||||||||||
| 31 | # | ||||||||||
| 32 | |||||||||||
| 33 | |||||||||||
| 34 | ###################################################################### | ||||||||||
| 35 | # Methods | ||||||||||
| 36 | # | ||||||||||
| 37 | |||||||||||
| 38 | |||||||||||
| 39 | sub addObjects | ||||||||||
| 40 | 7 | ▶ | { | ||||||||
|
Subroutine
addObjects: called CC=6 SCAR=17.9
Pod
undocumented
| |||||||||||
| 41 | 7 | my $self = shift(); | |||||||||
| 42 | 7 | my( @addObjects ) = @_; | |||||||||
| 43 | |||||||||||
| 44 | 7 | my $setHash = $self->_getAttr( '_setHash' ); | |||||||||
| 45 | 7 | my $setList = $self->_getAttr( '_setList' ); | |||||||||
| 46 | |||||||||||
| 47 | 7 | ▶ | if( ! defined( $setHash ) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 48 | { | ||||||||||
| 49 | 4 | $setHash = $self->_setAttr( '_setHash', {} ); | |||||||||
| 50 | 4 | $setList = $self->_setAttr( '_setList', [] ); | |||||||||
| 51 | } | ||||||||||
| 52 | |||||||||||
| 53 | 7 | my $addedCount = 0; | |||||||||
| 54 | |||||||||||
| 55 | 7 | foreach my $object ( @addObjects ) | |||||||||
| 56 | { | ||||||||||
| 57 | 16 | ▶ | if( ! UNIVERSAL::isa( $object, "P4::OO" ) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 58 | { | ||||||||||
| 59 | 1 | throw E_Fatal( __PACKAGE__ . " can only be used to store P4::OO objects.\n" ); | |||||||||
| 60 | } | ||||||||||
| 61 | |||||||||||
| 62 | # If the object is a Set, dump the members of the Set onto the list instead | ||||||||||
| 63 | #TODO - what about a Set of Sets? | ||||||||||
| 64 | 15 | ▶ | if( UNIVERSAL::isa( $object, 'P4::OO::_Set' ) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 65 | { | ||||||||||
| 66 | 1 | push( @addObjects, $object->listObjects() ); | |||||||||
| 67 | 1 | next; | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | 14 | my $objectID = $object->_uniqueID(); | |||||||||
| 71 | |||||||||||
| 72 | 14 | ▶ | if( exists( $setHash->{$objectID} ) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 73 | { | ||||||||||
| 74 | # ignore any objects we already have | ||||||||||
| 75 | 1 | next; | |||||||||
| 76 | } | ||||||||||
| 77 | |||||||||||
| 78 | 13 | push( @{$setList}, $object ); | |||||||||
| 79 | 13 | $setHash->{$objectID} = $object; | |||||||||
| 80 | 13 | $addedCount++; | |||||||||
| 81 | } | ||||||||||
| 82 | |||||||||||
| 83 | 6 | return( $addedCount ); | |||||||||
| 84 | } | ||||||||||
| 85 | |||||||||||
| 86 | |||||||||||
| 87 | sub listObjects | ||||||||||
| 88 | 3 | ▶ | { | ||||||||
|
Subroutine
listObjects: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 89 | 3 | my $self = shift(); | |||||||||
| 90 | |||||||||||
| 91 | 3 | my $setList = $self->_getAttr( '_setList' ); | |||||||||
| 92 | 3 | ▶ | if( ! defined( $setList ) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 93 | { | ||||||||||
| 94 | 1 | $setList = []; | |||||||||
| 95 | } | ||||||||||
| 96 | |||||||||||
| 97 | # Try to provide calling flexibility here... this might not be a good thing. | ||||||||||
| 98 | 3 | return( @{$setList} ); | |||||||||
| 99 | } | ||||||||||
| 100 | |||||||||||
| 101 | sub listObjectIDs | ||||||||||
| 102 | 0 | ▶ | { | ||||||||
|
Subroutine
listObjectIDs: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 103 | 0 | my $self = shift(); | |||||||||
| 104 | |||||||||||
| 105 | 0 | return( map { $_->_uniqueID() } ( $self->listObjects() ) ); | |||||||||
| 106 | } | ||||||||||
| 107 | |||||||||||
| 108 | |||||||||||
| 109 | ###################################################################### | ||||||||||
| 110 | # Standard authorship and copyright for documentation | ||||||||||
| 111 | # | ||||||||||
| 112 | |||||||||||
| 113 | =head1 AUTHOR | ||||||||||
| 114 | |||||||||||
| 115 | David L. Armstrong <armstd@cpan.org> | ||||||||||
| 116 | |||||||||||
| 117 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 118 | |||||||||||
| 119 | P4::OO::_Set is Copyright (c)2010-2011, David L. Armstrong. | ||||||||||
| 120 | |||||||||||
| 121 | This module is free software; you can redistribute it and/or | ||||||||||
| 122 | modify it under the same terms as Perl itself, either Perl | ||||||||||
| 123 | version 5.8.8 or, at your option, any later version of Perl 5 | ||||||||||
| 124 | you may have available. | ||||||||||
| 125 | |||||||||||
| 126 | =head1 SUPPORT AND WARRANTY | ||||||||||
| 127 | |||||||||||
| 128 | This program is distributed in the hope that it will be | ||||||||||
| 129 | useful, but it is provided "as is" and without any expressed | ||||||||||
| 130 | or implied warranties. | ||||||||||
| 131 | |||||||||||
| 132 | =cut | ||||||||||
| 133 | |||||||||||
| 134 | 12 | 1; | |||||||||