Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bitfield types #131

Merged
merged 10 commits into from Mar 6, 2023
Merged

Bitfield types #131

merged 10 commits into from Mar 6, 2023

Conversation

tobyink
Copy link
Owner

@tobyink tobyink commented Jan 28, 2023

For things like:

package MyApp::Line {
  use Moo;
  use Types::Common -types;
  
  use Type::Tiny::Bitfield LineStyle => {
    RED         => 1,
    GREEN       => 2,
    BLUE        => 4,
    DOTTED      => 64,
  };
  
  has [ 'start', 'end' ] => (
    is       => 'ro',
    isa      => InstanceOf[ 'MyApp::Point' ],
  );
  
  has style => (
    is       => 'ro',
    isa      => LineStyle,
    default  => 0,
  );
}

# A solid purple line from $p1 to $p2...
#
my $line = MyApp::Line->new(
  start    => $p1,
  end      => $p2,
  style    => MyApp::Line::LINESTYLE_RED | MyApp::Line::LINESTYLE_BLUE,
);

# A dotted green line:
#
my $s = MyApp::Line::LineStyle();
my $line2 = MyApp::Line->new(
  start    => $p3,
  end      => $p4,
  style    => $s->GREEN | $s->DOTTED,
);

Setting the style attribute to 8 would be a type error as there's no way to combine RED, BLUE, GREEN, and DOTTED to make 8.

@codecov
Copy link

codecov bot commented Jan 28, 2023

Codecov Report

Merging #131 (0f21482) into master (d5248b7) will increase coverage by 0.06%.
The diff coverage is 94.17%.

@@            Coverage Diff             @@
##           master     #131      +/-   ##
==========================================
+ Coverage   91.77%   91.84%   +0.06%     
==========================================
  Files          29       30       +1     
  Lines        3525     3628     +103     
  Branches      882      902      +20     
==========================================
+ Hits         3235     3332      +97     
  Misses          5        5              
- Partials      285      291       +6     
Impacted Files Coverage Δ
lib/Type/Tiny/Bitfield.pm 94.17% <94.17%> (ø)

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@tobyink tobyink merged commit 9293740 into master Mar 6, 2023
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Jun 30, 2023
Upstream changes:
2.004000        2023-04-05

 [ Documentation ]
 - Document that the `BoolLike` type is unstable.
 - Minor pod changes to Types::Standard.

 [ Packaging ]
 - Summarized the change log for versions prior to Type::Tiny 2.000000. If
   you need more information, see the Changes file included with Type::Tiny
   2.002001.
   <https://metacpan.org/release/TOBYINK/Type-Tiny-2.002001/source/Changes>

2.003_000       2023-04-02

 [ Documentation ]
 - Add SYNOPSIS for Type::Tiny::Class.
 - Add SYNOPSIS for Type::Tiny::Duck.
 - Add SYNOPSIS for Type::Tiny::Enum.
 - Add SYNOPSIS for Type::Tiny::Intersection.
 - Add SYNOPSIS for Type::Tiny::Role.
 - Add SYNOPSIS for Type::Tiny::Union.
 - Add documentation and tests for the combination of the `goto_next` and
   `multiple` options when used with `signature_for`.
 - Add example of `signature_for` applying a signature to multiple
   functions at once.
 - Document changes to `make_immutable` in Type::Library v2.x.
   <tobyink/p5-type-tiny#129>

 [ Other ]
 - Added: Type::Tiny now has an `exception_class` attribute, allowing a
   type to throw exceptions using a custom class. These classes should
   usually be a subclass of Error::TypeTiny::Assertion.
   <tobyink/p5-type-tiny#133>
 - Added: Type::Tiny::Bitfield class.
   <tobyink/p5-type-tiny#131>
 - Added: Types::TypeTiny::BoolLike type constraint.
   <tobyink/p5-type-tiny#137>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant