IOR.pm untested

filter: Statementstmt 0.0% 0 / 56 Branchbran 0.0% 0 / 10 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 78 CC 6 SCAR 19.8
CC
6
Cov
0%
parseIOR
12.0
printHash
12.0
stringifyIOR
6.0
CRAP 7.2
1 package CORBA::IOP::IOR;
2  
3 require 5.001;
4  
5 use CORBA::IOP::TaggedProfile;
6 use CORBA::IOP::Util;
7  
8 use strict;
9  
10 $IOR::VERSION='0.1';
11  
12  
13 sub new {
14 my $class = shift;
15 my $self = {};
16  
17 return bless $self, $class;
18 }
19  
20  
21 sub parseIOR {
22 my $self = shift;
23  
24 my ($ior) = @_;
25  
26 my ($prefix, $byte, $profiles_len);
27  
28 $prefix = unpack("a4", $ior);
29  
30 if ($prefix ne $IOR_MAGIC) {
31 die "Invalid IOR.";
32 }
33  
34 $ior = substr($ior, 4);
35 $byte = 0;
36  
37 ($self->{little_endian}, $byte) = decode_number($ior, $byte, 1, 0);
38  
39 ($self->{type_id}, $byte) = decode_string($ior, $byte, $self->{little_endian});
40  
41 ($profiles_len, $byte) = decode_number($ior, $byte, 4, $self->{little_endian});
42  
43 # search for IIOP profile (skip other profiles)
44 while($profiles_len--) {
45 my ($profile_id, $profile_data_len);
46  
47 ($profile_id, $byte) = decode_number($ior, $byte, 4, $self->{little_endian});
48
49 # next is the length of the 'profile_data' encapsulation
50 ($profile_data_len, $byte) = decode_number($ior, $byte, 4, $self->{little_endian});
51  
52 if ($profile_id == $TAG_INTERNET_IOP) {
53 # Found an IIOP profile.
54 $self->{IIOP_profile} = new CORBA::IOP::TaggedProfile;
55 $self->{IIOP_profile}->parseIOR($ior, $byte, $self->{little_endian});
56 }
57 else {
58 print "Unknown profile ID: $profile_id\n";
59 }
60  
61 $byte += $profile_data_len;
62 }
63 }
64  
65  
66 sub printHash {
67 my $self = shift;
68  
69 my ($key, $value);
70  
71 while (($key, $value) = each %$self) {
72 print "$key = $value\n" unless $key eq "IIOP_profile";
73 }
74  
75 if ($self->{IIOP_profile}) {
76 $self->{IIOP_profile}->printHash();
77 }
78 }
79  
80  
81 sub stringifyIOR {
82 my $self = shift;
83  
84 my ($ior, $string, $stringifiedProfile);
85  
86 $ior = "";
87  
88 $ior .= encode_number(length($ior), 1, 0, $self->{little_endian});
89  
90 $ior .= encode_string(length($ior), $self->{little_endian}, $self->{type_id});
91  
92 if (!$self->{IIOP_profile}) {
93 die "No IIOP profile set."
94 }
95  
96 # Hard code, only one profile.
97 $ior .= encode_number(length($ior), 4, $self->{little_endian}, 1);
98  
99 # And its IIOP.
100 $ior .= encode_number(length($ior), 4, $self->{little_endian}, $TAG_INTERNET_IOP);
101  
102 # Make it.
103 $stringifiedProfile = $self->{IIOP_profile}->stringifyIOR(length($ior), $self->{little_endian});
104  
105 # Encode profile length.
106 $ior .= encode_number(length($ior), 4, $self->{little_endian}, length($stringifiedProfile)/2);
107  
108 # Add profile on.
109 $ior .= $stringifiedProfile;
110  
111 return $IOR_MAGIC . $ior;
112 }
113  
114  
115 1;