| 1 | # Net::SDEE::Session.pm | ||||||||||||||||||||||||||||
| 2 | # | ||||||||||||||||||||||||||||
| 3 | # $Id: Session.pm,v 1.1 2004/12/23 12:02:30 jminieri Exp $ | ||||||||||||||||||||||||||||
| 4 | # | ||||||||||||||||||||||||||||
| 5 | # Copyright (c) 2004 Joe Minieri <jminieri@mindspring.com> and OpenService (www.open.com). | ||||||||||||||||||||||||||||
| 6 | # All rights reserved. | ||||||||||||||||||||||||||||
| 7 | # This program is free software; you can redistribute it and/or modify it under the same | ||||||||||||||||||||||||||||
| 8 | # terms as Perl itself. | ||||||||||||||||||||||||||||
| 9 | # | ||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | package Net::SDEE::Session; | ||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use 5.006001; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 1 | ▶ | use MIME::Base64; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | 1 | ▶ | use LWP::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 1 | my @_uri_parameters = ( 'Scheme', 'Server', 'Port', 'Username', 'Password', 'Path' ); | |||||||||||||||||||||||||||
| 21 | 1 | my @_http_header = ( 'UserAgent', 'Authorization' ); | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 1 | our $VERSION = '0.01'; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | ########################################################################################## | ||||||||||||||||||||||||||||
| 26 | # | ||||||||||||||||||||||||||||
| 27 | # AUTOLOAD get/set methods when they're generic | ||||||||||||||||||||||||||||
| 28 | # | ||||||||||||||||||||||||||||
| 29 | 1 | ▶ | use vars '$AUTOLOAD'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 30 | 0 | ▶ | sub AUTOLOAD { | ||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: not called CC=4 SCAR=27.3
| |||||||||||||||||||||||||||||
| 31 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | 0 | my ($self, $value) = @_; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | my $method =($AUTOLOAD =~ /.*::([_\w]+)$/)[0]; | |||||||||||||||||||||||||||
| 35 | 0 | ▶ | return if $method eq 'DESTROY'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | unless(defined($method) and exists($self->{ $method })) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
defined $method and exists $self->{$method}
MC/DC0%0/2
defined $method and exists $self->{$method}
defined $method
exists $self->{$method}
Truth table0%0/3
A and B
A= defined $methodB= exists $self->{$method}
| |||||||||||||||||||||||||||||
| 38 | 0 | $self->error(1); | |||||||||||||||||||||||||||
| 39 | 0 | $self->errorString("No such parameter $method"); | |||||||||||||||||||||||||||
| 40 | 0 | return undef; | |||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | # set this up for next time | ||||||||||||||||||||||||||||
| 44 | 0 | ▶ | *{$AUTOLOAD} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 45 | 0 | my ($self, $value) = @_; | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | if (defined($value)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 0 | return $self->{ $method } = $value; | |||||||||||||||||||||||||||
| 48 | } else { | ||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return defined($self->{ $method })?$self->{ $method }:undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | 0 | }; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | goto &$AUTOLOAD; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | # | ||||||||||||||||||||||||||||
| 56 | ########################################################################################## | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | ########################################################################################## | ||||||||||||||||||||||||||||
| 59 | # | ||||||||||||||||||||||||||||
| 60 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | 0 | my $caller = shift; | |||||||||||||||||||||||||||
| 62 | 0 | my %attr = @_; | |||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | 0 | ▶ | my $class = (ref($caller) or $caller); | ||||||||||||||||||||||||||
|
Condition0%0/3
ref $caller || $caller
MC/DC0%0/2
ref $caller || $caller
ref $caller
$caller
Truth table0%0/3
A || B
A= ref $callerB= $caller
| |||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | my $self = bless { | |||||||||||||||||||||||||||
| 67 | # connection parameters | ||||||||||||||||||||||||||||
| 68 | 'Scheme', 'https', | ||||||||||||||||||||||||||||
| 69 | 'Server', '127.0.0.1', | ||||||||||||||||||||||||||||
| 70 | 'Port', 443, | ||||||||||||||||||||||||||||
| 71 | 'Path', '/cgi-bin/sdee-server', | ||||||||||||||||||||||||||||
| 72 | 'UserAgent', 'SDEE Client/1.0', | ||||||||||||||||||||||||||||
| 73 | 'Authorization', undef, | ||||||||||||||||||||||||||||
| 74 | 'Username', 'username', | ||||||||||||||||||||||||||||
| 75 | 'Password', 'password', | ||||||||||||||||||||||||||||
| 76 | # subscription parameters | ||||||||||||||||||||||||||||
| 77 | 'Cookie', undef, | ||||||||||||||||||||||||||||
| 78 | 'sessionId', undef, | ||||||||||||||||||||||||||||
| 79 | 'state', 'closed', #is this per subscription or session? | ||||||||||||||||||||||||||||
| 80 | 'Type', 'subscription', | ||||||||||||||||||||||||||||
| 81 | 'error', undef, | ||||||||||||||||||||||||||||
| 82 | 'errorString', undef | ||||||||||||||||||||||||||||
| 83 | }, $class; | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | foreach my $attribute ( keys %attr ) { | |||||||||||||||||||||||||||
| 86 | 0 | $self->$attribute( $attr{ $attribute }); | |||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | #if(defined($self->{debug})) { $DEBUG_FLAG = 1; } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | $self->state('closed'); | |||||||||||||||||||||||||||
| 92 | 0 | $self->error(undef); | |||||||||||||||||||||||||||
| 93 | 0 | $self->errorString(undef); | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 0 | return $self; | |||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | # | ||||||||||||||||||||||||||||
| 99 | ########################################################################################## | ||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||
| 101 | ########################################################################################## | ||||||||||||||||||||||||||||
| 102 | # | ||||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub getURL { | ||||||||||||||||||||||||||
|
Subroutine
getURL: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 104 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | my $URI = URI->new(); | |||||||||||||||||||||||||||
| 107 | 0 | $URI->scheme( $self->Scheme ); | |||||||||||||||||||||||||||
| 108 | 0 | $URI->host( $self->Server ); | |||||||||||||||||||||||||||
| 109 | 0 | ▶ | unless($self->Port == 443) { $URI->port( $self->Port ); } | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 110 | 0 | $URI->path( $self->Path ); | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | return $URI->as_string; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub getHeader { | ||||||||||||||||||||||||||
|
Subroutine
getHeader: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 116 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | ▶ | unless(defined($self->Authorization)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 119 | 0 | $self->Authorization('Basic ' . | |||||||||||||||||||||||||||
| 120 | MIME::Base64::encode( $self->Username . ':' . $self->Password, '')); | ||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | my %headers = ( | |||||||||||||||||||||||||||
| 124 | 'User-Agent' => $self->UserAgent, | ||||||||||||||||||||||||||||
| 125 | 'Authorization' => $self->Authorization | ||||||||||||||||||||||||||||
| 126 | ); | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | 0 | ▶ | if(defined($self->Cookie)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 129 | 0 | $headers{ Cookie } = $self->Cookie; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | return \%headers; | |||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | # | ||||||||||||||||||||||||||||
| 137 | ########################################################################################## | ||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 1 | 1; | |||||||||||||||||||||||||||
| 140 | __END__ | ||||||||||||||||||||||||||||