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 3979884
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:13:29+00:00 2026-05-20T05:13:29+00:00

I am trying to extend Set::Object in order to allow type constraint checking when

  • 0

I am trying to extend Set::Object in order to allow type constraint checking when inserting objects. My class so far looks like this:

package My::Set::Object;

use strict;
use warnings;

use Moose;
use MooseX::NonMoose;
extends 'Set::Object';

has type => (is => 'ro', isa => 'Str', required => 1);

before [ qw(insert invert intersection union) ] => sub {
my ($self,$list) = @_;

for (@$list) {
    confess "Only ",$self->type," objects are allowed " unless $_->does($self->type);
}
};

no Moose;
__PACKAGE__->meta->make_immutable;

Unfortunately, it appears that the construction arguments are passed through to Set::Object as well when i do the following example object construction

my $set = My::Set::Object->new(type => 'Foo::Bar');

After printing out the contents of set, i find that “type” and “Foo::Bar” are members of the set.

How can i fix this? Or is there perhaps an easier way of doing this?

  • 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-20T05:13:29+00:00Added an answer on May 20, 2026 at 5:13 am

    Here, as an actual answer. I usually code along these lines and should do what you need. Warning: I haven’t tested this code, it may not even compile, but it should get you on the right track. The only real difference with this vs subclassing is ->ISA on your My::Set::Object objects is not going to be true when checking for ‘Set::Object’.

    package My::Set::Object;
    
    use strict;
    use warnings;
    
    use Moose;
    use Set::Object;
    
    my @methods = qw/insert includes has contains invert intersection union/; # etc etc.
    
    has type => (is => 'ro', isa => 'Str', required => 1);
    has _so => (is => 'ro', isa => 'Set::Object', handles => \@methods, lazy_build => 1);
    
    before [ qw(insert invert intersection union) ] => sub {
      my ($self,$list) = @_;
    
      for (@$list) {
        confess "Only ",$self->type," objects are allowed " unless $_->does($self->type);
      }
    };
    
    sub _build__so {
      return Set::Object->new()
    }
    no Moose;
    __PACKAGE__->meta->make_immutable;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I am trying extend the base Application class and add member variables to
I've been trying to extend SimplePie to sort a feed in reverse order. The
I'm Trying to extend a non-moose class, and when I call an accessor defined
I am trying to extend the mysqli class to make a helper class that
In this JSON-P callback I'm trying to extend the object called bounds (declared earlier)
I'm trying to get the record ID from the underlying object set on the
I am trying to extend the Paging property of our Gridview to allow a
I am trying to set up a class with commonly used tasks, such as
I'm trying to make an object act like a built-in list , except that
I'm trying to encapsulate my game objects by having them extend Mircosoft.Xna.Framework.GameCompenent, then merely

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.