Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6032673
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:22:07+00:00 2026-05-23T05:22:07+00:00

Hello fellow Perl users, I’d like to move few Perl classes from a card

  • 0

Hello fellow Perl users,

I’d like to move few Perl classes from a card game to Class::Struct, because 1) I’d like to have some type checking in my classes and 2) Damian Conway is one of the module authors and that man is great (seen him talking at Perl conferences 10y ago). But I wonder, how to solve 3 problems with the constructor in the following class:

package User;

our %Users;
our $LobbyPos = 0;

# the bit positions for the recently changed fields
use constant MOUNT      => 1 << 0;
use constant POOL       => 1 << 1;
use constant WHIST1     => 1 << 2;
use constant WHIST2     => 1 << 3;

sub new {
        my $pkg  = shift;
        my $id   = shift;
        my $auth = shift;

        my $user = {

                ID              => $id,
                AUTH            => $auth,
                LOBBY_POS       => (++$LobbyPos % 3),
                # NAME, NICK, INFO will be updated later by login()
                NAME            => $id,
                NICK            => $id,
                INFO            => sprintf('id="%s"', $id),
                CHAT            => [],
                KIB             => undef,
                GAME            => undef,
                CHILD           => undef,
                SEAT            => 0,
                HAND            => {},
                HAND_STR        => '',
                NTRIX           => 0,
                ALLOWED         => [],
                BID             => 0,
                BID1            => 0,
                CARD            => undef,
                LAST_READ       => time(),
                TIMER           => undef,
                PREV            => [],

                BACK            => 0,
                AGREE           => 0,
                REVEAL          => 0,
                ONEMORE         => 0,

                MONEY           => 0,
                OLD_MONEY       => 0,
                CHANGED         => 0,
                MOUNT           , [],
                POOL            , [],
                WHIST1          , [],
                WHIST2          , [],

                STATS_PASS      => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                STATS_MISERE    => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                STATS_LUCK      => [0, 0, 0, 0, 0, 0, 0],
                STATS_GAME      => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
                STATS_MATCH     => [0, 0, 0, 0],
        };

        $Users{$id} = $user;
        bless($user, $pkg);
}

Problem 1: my new receives 2 arguments – $id and $auth – and they’re used to initiate several members. I probably know how to solve it by looking at Example 3 in perldoc Class:Struct.

Problem 2: I use global variable $LobbyPos to set another member, and also set one more member to epoch seconds time()

Problem 3: I have 4 numeric members MOUNT, POOL, WHIST1, WHIST2 in my object. There is probably no way to continue using them so – once I start using Class::Struct?

Any comments (esp. on Problem 2 – because I have more classes which use global variables to set members in their constructors) are welcome,

Thank you!
Alex

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T05:22:08+00:00Added an answer on May 23, 2026 at 5:22 am

    Class::Struct hasn’t been updated for ten years. I’m pretty sure that it’s only still included in the Perl core for backwards compatibility. I really wouldn’t recommend that anyone ports code to Class::Struct these days.

    Instead I’d highly recommend that you investigate moving your code to Moose. Moose is the future of OO Programming in Perl.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello stackoverflow fellow members? Struct Declaration in class A struct PointSprite { GLfloat x;
Hello fellow programmers, got a few problem here. I am adding a user control
Hello Again my fellow programmers out there, I'm designing and programming from scratch a
Hello fellow programmers I have been searching the internet for a few days now
Hello Fellow Matlab Users, I was wondering if anyone could provide me with some
Hello fellow Stackoverflow users, I have a page which does a AJAX request to
Hello fellow StackOverflow users (or Stackoverflowers ?): I'm learning-by-coding WPF. I read several articles/saw
Hello fellow stackoverflow members! I'm very new to the C# language transfer from Java,
hello fellow java developers. I'm having a bit of an issue here. I have
Hello fellow software developers. I want to distribute a C program which is scriptable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.