| 1 | ###################################################################### | ||||||||||
| 2 | # Copyright (c)2010-2011, David L. Armstrong. | ||||||||||
| 3 | # | ||||||||||
| 4 | # P4::OO::_SpecObj.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 | # Package Initialization | ||||||||||
| 21 | # | ||||||||||
| 22 | package P4::OO::_SpecObj; | ||||||||||
| 23 | 11 | our $VERSION = '0.00_02'; | |||||||||
| 24 | 11 | ▶ | use base 'P4::OO'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 25 | 11 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 26 | |||||||||||
| 27 | |||||||||||
| 28 | ###################################################################### | ||||||||||
| 29 | # Globals | ||||||||||
| 30 | # | ||||||||||
| 31 | # Not listed here, but we leverage the P4::OO Class Global | ||||||||||
| 32 | # P4::OO::PERFORCE_TRANSLATION_TABLE also | ||||||||||
| 33 | |||||||||||
| 34 | # Subclasses must define SPECOBJ_TYPE | ||||||||||
| 35 | 0 | ▶ | sub SPECOBJ_TYPE { return( undef ); } | ||||||||
|
Subroutine
SPECOBJ_TYPE: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 36 | |||||||||||
| 37 | |||||||||||
| 38 | ###################################################################### | ||||||||||
| 39 | # Methods | ||||||||||
| 40 | # | ||||||||||
| 41 | |||||||||||
| 42 | sub _uniqueID | ||||||||||
| 43 | 0 | ▶ | { | ||||||||
|
Subroutine
_uniqueID: not called CC=1 SCAR=6.9
| |||||||||||
| 44 | 0 | my $self = shift(); | |||||||||
| 45 | |||||||||||
| 46 | 0 | return( $self->_getSpecID() ); | |||||||||
| 47 | } | ||||||||||
| 48 | |||||||||||
| 49 | sub _getSpecID | ||||||||||
| 50 | 0 | ▶ | { | ||||||||
|
Subroutine
_getSpecID: not called CC=2 SCAR=17.9
| |||||||||||
| 51 | 0 | my $self = shift(); | |||||||||
| 52 | |||||||||||
| 53 | 0 | my $specID = $self->_getAttr( 'id' ); | |||||||||
| 54 | |||||||||||
| 55 | 0 | ▶ | if( ! defined( $specID ) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 56 | { | ||||||||||
| 57 | 0 | $self->__initialize(); | |||||||||
| 58 | 0 | $specID = $self->_getAttr( 'id' ); | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | # If specID is still undef, oh well. | ||||||||||
| 62 | 0 | return( $specID ); | |||||||||
| 63 | } | ||||||||||
| 64 | |||||||||||
| 65 | sub _getSpecAttr | ||||||||||
| 66 | 0 | ▶ | { | ||||||||
|
Subroutine
_getSpecAttr: not called CC=4 SCAR=30.0
| |||||||||||
| 67 | 0 | my $self = shift(); | |||||||||
| 68 | 0 | my( $attrName ) = @_; | |||||||||
| 69 | 0 | my $subName = ( caller( 0 ) )[3]; | |||||||||
| 70 | |||||||||||
| 71 | 0 | ▶ | if( ! defined( $attrName ) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 72 | { | ||||||||||
| 73 | 0 | my $caller = ( caller( 1 ) )[3]; | |||||||||
| 74 | 0 | throw E_P4Fatal "$subName: attrName not specified by $caller.\n"; | |||||||||
| 75 | } | ||||||||||
| 76 | |||||||||||
| 77 | # Make sure the spec is loaded | ||||||||||
| 78 | 0 | $self->__initialize(); | |||||||||
| 79 | 0 | my $p4Spec = $self->_getAttr( 'p4Spec' ); | |||||||||
| 80 | |||||||||||
| 81 | # Allow the caller to use any case for the spec attribute | ||||||||||
| 82 | 0 | my $lcAttrName = lc( $attrName ); | |||||||||
| 83 | |||||||||||
| 84 | # P4PERL (and all P4::OO::_Connection subclasses) provide the _fields_ | ||||||||||
| 85 | # hash as an index to find the actual attribute key using all lowercase | ||||||||||
| 86 | 0 | ▶ | if( ! exists( $p4Spec->{'_fields_'}->{$lcAttrName} ) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | { | ||||||||||
| 88 | 0 | my $specType = $self->SPECOBJ_TYPE(); | |||||||||
| 89 | 0 | throw E_P4Fatal "$subName: Invalid Spec attribute $attrName for type $specType.\n"; | |||||||||
| 90 | } | ||||||||||
| 91 | |||||||||||
| 92 | 0 | my $p4AttrName = $p4Spec->{'_fields_'}->{$lcAttrName}; | |||||||||
| 93 | |||||||||||
| 94 | 0 | ▶ | if( exists( $p4Spec->{$p4AttrName} ) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 95 | { | ||||||||||
| 96 | # Avoid autovivification against P4::Spec objects | ||||||||||
| 97 | 0 | return( $p4Spec->{$p4AttrName} ); | |||||||||
| 98 | } | ||||||||||
| 99 | |||||||||||
| 100 | 0 | return( undef ); | |||||||||
| 101 | } | ||||||||||
| 102 | |||||||||||
| 103 | sub _setSpecAttr | ||||||||||
| 104 | 0 | ▶ | { | ||||||||
|
Subroutine
_setSpecAttr: not called CC=1 SCAR=6.9
| |||||||||||
| 105 | 0 | my $self = shift(); | |||||||||
| 106 | |||||||||||
| 107 | # Make sure the spec is loaded | ||||||||||
| 108 | 0 | $self->__initialize(); | |||||||||
| 109 | |||||||||||
| 110 | #TODO... | ||||||||||
| 111 | } | ||||||||||
| 112 | |||||||||||
| 113 | ###################################################################### | ||||||||||
| 114 | # Internal (private) methods | ||||||||||
| 115 | # | ||||||||||
| 116 | sub __initialize | ||||||||||
| 117 | 0 | ▶ | { | ||||||||
|
Subroutine
__initialize: not called CC=2 SCAR=17.9
| |||||||||||
| 118 | 0 | my $self = shift(); | |||||||||
| 119 | |||||||||||
| 120 | 0 | my $p4Spec = $self->_getAttr( 'p4Spec' ); | |||||||||
| 121 | 0 | ▶ | if( ! defined( $p4Spec ) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 122 | { | ||||||||||
| 123 | # Need to ask our connection to download the spec for us. | ||||||||||
| 124 | 0 | my $specID = $self->_getAttr( 'id' ); | |||||||||
| 125 | |||||||||||
| 126 | # Need to ask our connection to download spec for us. | ||||||||||
| 127 | 0 | my $p4ConnObj = $self->_getP4Connection(); | |||||||||
| 128 | 0 | my $p4Spec = $p4ConnObj->readSpec( $self ); | |||||||||
| 129 | } | ||||||||||
| 130 | |||||||||||
| 131 | 0 | return( $p4Spec ); | |||||||||
| 132 | } | ||||||||||
| 133 | |||||||||||
| 134 | ###################################################################### | ||||||||||
| 135 | # Standard authorship and copyright for documentation | ||||||||||
| 136 | # | ||||||||||
| 137 | |||||||||||
| 138 | =head1 AUTHOR | ||||||||||
| 139 | |||||||||||
| 140 | David L. Armstrong <armstd@cpan.org> | ||||||||||
| 141 | |||||||||||
| 142 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 143 | |||||||||||
| 144 | P4::OO::_SpecObj is Copyright (c)2010-2011, David L. Armstrong. | ||||||||||
| 145 | |||||||||||
| 146 | This module is free software; you can redistribute it and/or | ||||||||||
| 147 | modify it under the same terms as Perl itself, either Perl | ||||||||||
| 148 | version 5.8.8 or, at your option, any later version of Perl 5 | ||||||||||
| 149 | you may have available. | ||||||||||
| 150 | |||||||||||
| 151 | =head1 SUPPORT AND WARRANTY | ||||||||||
| 152 | |||||||||||
| 153 | This program is distributed in the hope that it will be | ||||||||||
| 154 | useful, but it is provided "as is" and without any expressed | ||||||||||
| 155 | or implied warranties. | ||||||||||
| 156 | |||||||||||
| 157 | =cut | ||||||||||
| 158 | |||||||||||
| 159 | 11 | 1; | |||||||||