Confused Still by Hash Refs
hesco
created: 2006-02-03 02:22:58
I'm still working to learn to use DBIx::UserDB.

My browser reports:

Software error:

Can't use string ("wheel") as a HASH ref while "strict refs" in use at /usr/local/share/perl/5.8.7/DBIx/UserDB.pm line 410.
Here is the debugging output I'm sending to the error log:

New UserDB object created.
The $session ID is:
77540362YTIvQiAaOS7yA942A153i62p32351f159U25f59k22l181r1112198r113k146y85A21O160w104393P643515121S122n190n96A21067w174n66c98l100j95w174e13j125g293123n96B60G9EPZdZYJ4zjW1.
About to enter dispatch code.
$function is NewGroup.
[Thu Feb  2 22:29:32 2006] test-auth5.cgi: Odd number of elements in hash assignment at /var/wwwssl/auth-test/test-auth5.cgi line 379.
GroupCreate received these arguments:
        $userdb is DBIx::UserDB=HASH(0x84febec).
        The new group name is: wheel.
        $group is HASH(0x84fecac).
Creating a new group called:  wheel.
        ref of group = ref(HASH(0x84fecac))
        ref of groupname = ref(wheel)
[Thu Feb  2 22:29:32 2006] test-auth5.cgi: Can't use string ("wheel") as a HASH ref while "strict refs" in use at /usr/local/share/perl/5.8.7/DBIx/UserDB.pm line 410.
I'm using this syntax:

   &GroupCreate($userdb,\%group);
to call a subroutine which includes line 379, the line which accepts @_ and parses it at the top of the following snippet.

sub GroupCreate() {
  my($userdb,%group) = @_;
  print STDERR "GroupCreate received these arguments: \n\t\$userdb is $userdb.  \n\tThe new group name is: $group->{groupname}.\n\t\$group is $group.\n";
  return p("Groupname required to create new group.") unless defined($group->{groupname});
  my($status,$gid);
  print STDERR "Creating a new group called: $group->{groupname}.\n";

  print STDERR "\tref of group = ref($group) \n\tref of groupname = ref($groupname) \n";

  {
    no strict 'refs';
    my $result = $userdb->group_create ( $group->{groupname} );
  }
  if($result) {
    $status = p("A New Group, called $group{groupname} has been successfully created, with GID: $group->{'gid
'}.");
  } else {
    $status = p("The creation of a new Group, called $group{groupname} failed.");
  }
  return $status;
} # END GroupCreate
And line 410 which throws that other error is in this subroutine in a distinct module, on the line which defines $old_group.

sub group_create {
    my ( $self, $group ) = @_;

    my $DB = $self->{DB};

    # Check for group with same name
    my $old_group = $DB->record_search( $self->{group_profile},
                            { groupname => $group->{groupname} }
                                );
    return undef if @$old_group;

    $DB->record_insert( $self->{group_profile}, $group );
    my $new_group = $DB->record_search( $self->{group_profile},
                            { groupname => $group->{groupname} }
                                );
    die "Failed to find newly created group\n" unless @$new_group == 1;

    # Copy the fields of the new user back in this one
    while ( my ($name,$value) = each %{$new_group->[0]} ) {
        $group->{$name} = $value;
    }

    return $group;
}
If this is too confusing to be helpful and you've successfully used DBIx::UserDB, I'd be happy for the moment simply having some working code snippets I could adapt from.

-- Hugh

Re: Confused Still by Hash Refs
created: 2006-02-03 02:42:22
FYI, that groupname gets passed, using CGI, like so:
my $groupname = $q->param('groupname') || '';
my $group = { groupname => $groupname };
Re: Confused Still by Hash Refs
g0n
created: 2006-02-03 07:06:00
Your problem is this:

  my($userdb,%group) = @_;
if you are calling it with this:

  &GroupCreate($userdb,\%group);

You are sending the sub a scalar (I assume) and a hashref, but the assignment

  my($userdb,%group) = @_;
is expecting a list. As an alternative, try:
  my ($userdb,$groupref) = @_;
  my %group = %$groupref;

--------------------------------------------------------------

"If there is such a phenomenon as absolute evil, it consists in treating another human being as a thing."
John Brunner, "The Shockwave Rider".

Re^2: Confused Still by Hash Refs
created: 2006-02-03 07:22:13
Thank you, sir. That handled the error in test-auth5.cgi at line 379, the "odd number of elements in hash assignment" piece. It leaves me with the hash ref error in the module I'm trying to use, suggesting to me that I'm not sending DBIx::UserDB its arguments in exactly the right manner, somehow. Any further ideas? -- Hugh
Re^3: Confused Still by Hash Refs
g0n
created: 2006-02-03 07:33:44
Yep, take a look at [cpan://DBIx::Userdb]. The syntax is:

group_create(\%hash);

and you're doing:

$userdb->group_create ( $group->{groupname} )

$group->{groupname} isn't a hashref, in fact AFAICT it is the value 'wheel'. Try this:

$userdb->group_create($group);

or

$userdb->group_create({groupname=>$group->{groupname}});

if you don't want to pass the rest of the contents of %$group in.

--------------------------------------------------------------

"If there is such a phenomenon as absolute evil, it consists in treating another human being as a thing."
John Brunner, "The Shockwave Rider".

perlmonks.org content © perlmonks.org and g0n, hesco

prlmnks.org © 2006 edmund von der burg (eccles & toad)

v 0.03