#!/usr/bin/perl
# dbipg_dbsession
#    $Id: dbipg_dbsession,v 1.2 2002/12/30 13:29:09 nakahira Exp $
#    Last updated: 12/30/2002
#
# Copyright (C) 2002 The Nagoya University Consumers' Co-operative Association
#   Written by K.Nakahira
#
#  This program is licensed under the GNU GPL.
#  See the following URL for more details:
#    http://www.gnu.org/licenses/gpl.txt
#

use strict;
use File::Basename;

use DBIPgSystem::DB;
use DBSession;

my $VERSION = '0.1.00';

# 
my $init = { basename => basename($0),
			 basedir => dirname($0),
		   };

sub usage {
  my $ver = "(version $VERSION)" if($VERSION);
  print <<USAGE;
$init->{basename} $ver
Usage: $init->{basename} conffile id
ARGS:
  conffile  ǡե
  id        åID
USAGE
  exit;
}

{
  &usage if(@ARGV != 2 or $ARGV[0] =~ m/^--?h(elp)?$/i);
  my ($conffile, $sid) = @ARGV;

  my $dbi = DBIPgSystem::DB->new($conffile, 'staff', 'root', test => 1);

  my $session = DBSession->new
	("dbi:Pg:$dbi->{global}{db}{data_source}",
	 $dbi->{global}{db}{username}, $dbi->{global}{db}{passwd}, $sid);
  die unless($session);

  my $ldate = $session->ldate;
  print "ldate = $ldate\n";

  my $data = $session->data;
  my ($key, $value);
  while(($key, $value) = each %$data) {
	&print_var($value, 0, "$key =");
  }
  undef $session;
}
exit;

sub print_var {
  # print_var   ѿɽ
  # ----------------------------------------------------------
  my ($in, $deep, $head) = @_;
  my $indent = '  ' x $deep++;

  $in = '(undef)' unless(defined $in);
  print "$indent$head $in\n";
  if(ref($in) eq '') {
	return;
  } elsif(ref($in) eq 'SCALAR') {
	&print_var($$in, $deep);
  } elsif(ref($in) eq 'ARRAY') {
	foreach my $i (0 .. $#$in) { &print_var($in->[$i], $deep, "[$i] ="); }
  } elsif(ref($in) eq 'HASH') {
	foreach my $k (sort keys %$in) {
	  &print_var($in->{$k}, $deep, "{$k} =");
	}
  } elsif(ref($in) eq 'REF') {
	&print_var($$in, $deep);
  }
}
exit;

__END__

=for html
<div class="header">
<div class="bar">
<a href="../index.html">Top</a>
<a href="index.html">ޥ˥奢</a>
</div>
<h1>dbipg_dbsession</h1></div>

=for html
<div class="pod">

=head1 NAME

dbipg_dbsession - å˳Ǽ줿ǡɽ

=head1 DESCRIPTION

  $ dbipg_dbsession id

ꤷIDΥå˳Ǽ줿ǡɽ롣

=head1 SEE ALSO

F<DBIPgSystem>, F<DBIPgSystem::DB>

=head1 COPYRIGHT

Copyright (C) 2002 The Nagoya University Consumers' Co-operative Association

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the following URL for more details:
  http://www.gnu.org/licenses/gpl.txt

Written by Kenji Nakahira <nakahira@coop.nagoya-u.ac.jp>

=for html
</div>

=cut

