File Coverage

blib/lib/P4/OO/_SpecObj.pm
Criterion Covered Total %
statement 6 40 15.0
branch 0 10 0.0
condition n/a
subroutine 2 8 25.0
pod 0 1 0.0
total 8 59 13.5


line stmt bran cond sub pod time code
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             our $VERSION = '0.00_02';
24 11     11   33963 use base 'P4::OO';
  11         25  
  11         6614  
25 11     11   58 use strict;
  11         24  
  11         5679  
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     0 0   sub SPECOBJ_TYPE { return( undef ); }
36              
37              
38             ######################################################################
39             # Methods
40             #
41              
42             sub _uniqueID
43             {
44 0     0     my $self = shift();
45              
46 0           return( $self->_getSpecID() );
47             }
48              
49             sub _getSpecID
50             {
51 0     0     my $self = shift();
52              
53 0           my $specID = $self->_getAttr( 'id' );
54              
55 0 0         if( ! defined( $specID ) )
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             {
67 0     0     my $self = shift();
68 0           my( $attrName ) = @_;
69 0           my $subName = ( caller( 0 ) )[3];
70              
71 0 0         if( ! defined( $attrName ) )
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 0         if( ! exists( $p4Spec->{'_fields_'}->{$lcAttrName} ) )
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 0         if( exists( $p4Spec->{$p4AttrName} ) )
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             {
105 0     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             {
118 0     0     my $self = shift();
119              
120 0           my $p4Spec = $self->_getAttr( 'p4Spec' );
121 0 0         if( ! defined( $p4Spec ) )
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
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             1;