The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
<html><head><title>Types::CLike</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" >
</head>
<body class='pod'>
<!--
  generated by Pod::Simple::HTML v3.22,
  using Pod::Simple::PullParser v3.22,
  under Perl v5.014002 at Thu Oct 10 00:28:10 2013 GMT.

 If you want to change this HTML document, you probably shouldn't do that
   by changing it directly.  Instead, see about changing the calling options
   to Pod::Simple::HTML, and/or subclassing Pod::Simple::HTML,
   then reconverting this document from the Pod source.
   When in doubt, email the author of Pod::Simple::HTML for advice.
   See 'perldoc Pod::Simple::HTML' for more info.

-->

<!-- start doc -->
<a name='___top' class='dummyTopAnchor' ></a>

<h1><a class='u'
name="NAME"
>NAME</a></h1>

<p>Types::CLike - C-like data types for Moo(se)</p>

<h1><a class='u'
name="SYNOPSIS"
>SYNOPSIS</a></h1>

<pre>    package MyPackage;
    use Moo;  # or Moose or Mouse
    use Types::CLike qw(:all);
 
    has &#39;foo&#39; =&#62; (
       isa =&#62; Int     # or Int32, Signed32
    );
    has &#39;bar&#39; =&#62; (
       isa =&#62; Short   # or SmallInt, Int16, Signed16
    );
 
    use Scalar::Util qw(blessed);
    use Math::BigFloat;
    use Sub::Quote;
 
    has &#39;baz&#39; =&#62; (
       isa =&#62; Double,  # or Float64, Binary64
 
       # A Double number gets pretty big, so make sure we use big numbers
       coerce =&#62; quote_sub q{
          Math::BigFloat-&#62;new($_[0])
             unless (blessed $_[0] =~ /^Math::BigFloat|^bignum/);
       },
    );</pre>

<h1><a class='u'
name="DESCRIPTION"
>DESCRIPTION</a></h1>

<p>Given the popularity of various byte-sized data types in C-based languages, databases, and computers in general, there&#39;s a need for validating those data types in Perl &#38; Moo(se). This module covers the gamut of the various number and character types in all of those forms.</p>

<p>The number types will validate that the number falls within the right bit length, that unsigned numbers do not go below zero, and &#34;Perl unsafe&#34; numbers are blessed. Blessed numbers are also checked to make sure they have an accuracy that supports the right number of significant decimal digits. (However, BigInt/Float defaults to 40 digits, which is above the 39 digits for 128-bit numbers, so you should be safe.)</p>

<p>Char types will validate that it&#39;s a single character, using Perl&#39;s Unicode-complaint <code>length</code> function. The bit check types will also check that the ASCII/Unicode code (<code>ord</code>) is the right bit length.</p>

<p>IEEE 754 decimal floating types are also available, which are floats that use a base-10 mantissa. And the SQL Server &#34;money&#34; types, which are basically decimal numbers stored as integers.</p>

<h1><a class='u'
name="TYPES"
>TYPES</a></h1>

<p>All available types (including lots of aliases) are listed below:</p>

<pre>    ### Integers ###
              [SIGNED]                                   | [UNSIGNED]
      4-bit = SNibble SSemiOctet Int4 Signed4            | Nibble SemiOctet UInt4 Unsigned4
      8-bit = SByte SOctet TinyInt Int8 Signed8          | Byte Octet UnsignedTinyInt UInt8 Unsigned8
     16-bit = Short SmallInt Int16 Signed16              | UShort UnsignedSmallInt UInt16 Unsigned16
     24-bit = MediumInt Int24 Signed24                   | UnsignedMediumInt UInt24 Unsigned24
     32-bit = Int Int32 Signed32                         | UInt UnsignedInt UInt32 Unsigned32
     64-bit = Long LongLong BigInt Int64 Signed64        | ULong ULongLong UnsignedBigInt UInt64 Unsigned64
    128-bit = SOctaWord SDoubleQuadWord Int128 Signed128 | OctaWord DoubleQuadWord UInt128 Unsigned128
 
    ### Floats (binary) ###
    (Total, Exponent) bits; Significand precision = Total - Exponent - 1 (sign bit)
 
    ( 16,  4) bits = ShortFloat
    ( 16,  5) bits = Half Float16 Binary16
    ( 32,  8) bits = Single Real Float Float32 Binary32
    ( 40,  8) bits = ExtendedSingle Float40
    ( 64, 11) bits = Double Float64 Binary64
    ( 80, 15) bits = ExtendedDouble Float80
    (104,  8) bits = Decimal    # not a IEEE 754 decimal, but C#&#39;s bizarre &#34;128-bit&#34; float
    (128, 15) bits = Quadruple Quad Float128 Binary128
 
    ### Floats (decimal) ###
    (Digits, Exponent Max)
 
    ( 7,   96) = Decimal32
    (16,  384) = Decimal64
    (34, 6144) = Decimal128
 
    ### &#34;Money&#34; ###
    (Bits, Scale)
 
    ( 32,  4) = SmallMoney
    ( 64,  4) = Money Currency
    (128,  6) = BigMoney  # doesn&#39;t exist; might change if it does suddenly exists
 
    ### Chars ###
    Bit check types = Char/Char8, Char16, Char32, Char48, Char64</pre>

<h1><a class='u'
name="EXPORTER_TAGS"
>EXPORTER TAGS</a></h1>

<p>Since there are so many different aliases in this module, using <code>:all</code> (while available) probably isn&#39;t a good idea. So, there are some Exporter tags available, grouped by language:</p>

<pre>    # NOTE: Some extra types are included to fill in the gaps for signed vs. unsigned and
    # byte vs. char.
 
    :c       = Char Byte Short UShort Int UInt Long ULong Float Double ExtendedDouble
    :stdint  = Int4 UInt4 ... Int128 UInt128 (except 24-bit)
    :c#      = SByte Byte Char16 Short UShort Int UInt Long ULong Float Double Decimal
    :ieee754 = Binary16,32,64,128 and Decimal32,64,128
    :tsql    = TinyInt SmallInt Int BigInt SmallMoney Money Float64 Real
    :mysql   = TinyInt SmallInt MediumInt Int BigInt (and Unsigned versions) Float Double
    :ansisql = SmallInt Int Float Real Double
 
    :is_*    = All of the is_* functions for that tag
    :*+is    = Both the Moo and is_* functions for that tag</pre>

<h1><a class='u'
name="CAVEATS"
>CAVEATS</a></h1>

<h2><a class='u'
name="Types::Numbers"
>Types::Numbers</a></h2>

<p>All of these types are basically aliases of parameterized types in <a href="http://search.cpan.org/perldoc?Types%3A%3ANumbers" class="podlinkpod"
>Types::Numbers</a>. Caveats of those types apply here. The types used are as follows:</p>

<pre>    SignedInt     # signed integers
    UnsignedInt   # unsigned integers
    FloatBinary   # binary floats
    FloatDecimal  # decimal floats
    FixedBinary   # money types
    Char          # char types</pre>

<h2><a class='u'
name="Type_namespace_conflicts"
>Type namespace conflicts</a></h2>

<p>Some types are also used by <a href="http://search.cpan.org/perldoc?Types%3A%3AStandard" class="podlinkpod"
>Types::Standard</a> and <a href="http://search.cpan.org/perldoc?Types%3A%3ANumbers" class="podlinkpod"
>Types::Numbers</a>, namely <code>Int</code> and <code>Char</code>. So be careful not to import them at the same time, as they have different meanings.</p>

<h2><a class='u'
name="Differences_between_CLike_and_real_data_types"
>Differences between CLike and real data types</a></h2>

<p>Most C-based languages use a <code>char</code> type to indicate both an 8-bit number and a single character, as all strings in those languages are represented as a series of character codes. Perl, as a dynamic language, has a single scalar to represent both strings and numbers. Thus, to separate the validation of the two, the term <code>Byte</code> or <code>Octet</code> means the numeric 8-bit types, and the term <code>Char</code> means the single character string types.</p>

<p>The term <code>long</code> in C/C++ is ambiguous depending on the bits of the OS: 32-bits for 32-bit OSs and 64-bits for 64-bit OSs. Since the 64-bit version makes more sense (ie: <code>short &#60; int &#60; long</code>), that is the designation chosen. To avoid confusion, you can just use <code>LongLong</code> and <code>ULongLong</code>.</p>

<p>The confusion is even worse for float types, with the <code>long</code> modifier sometimes meaning absolutely nothing in certain hardware platforms. <code>Long</code> isn&#39;t even used in this module for those types, in favor of IEEE 754&#39;s &#34;Extended&#34; keyword.</p>

<h2><a class='u'
name="Floats"
>Floats</a></h2>

<p>The floats will support infinity and NaN, since C floats support this. This may not be desirable, so you might want to subtype the float and test for Inf/NaN if you don&#39;t want these. Furthermore, the &#34;Perl safe&#34; scalar tests for floats include checks to make sure it supports Inf/NaN. However, the odds of it NOT supporting those (since Perl should be using IEEE 754 floats for NV) are practically zero.</p>

<p>Hopefully, I&#39;ve covered all possible types of floats found in the wild. If not, let me know and I&#39;ll add it in. (For that matter, let me know if I&#39;m missing <b>any</b> type found in the wild.)</p>

<h1><a class='u'
name="HISTORY"
>HISTORY</a></h1>

<p>This module started out as <a href="http://search.cpan.org/perldoc?MooX%3A%3ATypes%3A%3ACLike" class="podlinkpod"
>MooX::Types::CLike</a>. Since <a href="http://search.cpan.org/perldoc?Type%3A%3ATiny" class="podlinkpod"
>Type::Tiny</a> came about, that module has been translated to work with TT&#39;s API. Both <a href="http://search.cpan.org/perldoc?Types%3A%3ANumbers" class="podlinkpod"
>Types::Numbers</a> and this module are the result.</p>

<h1><a class='u'
name="AVAILABILITY"
>AVAILABILITY</a></h1>

<p>The project homepage is <a href="https://github.com/SineSwiper/Types-CLike/wiki" class="podlinkurl"
>https://github.com/SineSwiper/Types-CLike/wiki</a>.</p>

<p>The latest version of this module is available from the Comprehensive Perl Archive Network (CPAN). Visit <a href="http://www.perl.com/CPAN/" class="podlinkurl"
>http://www.perl.com/CPAN/</a> to find a CPAN site near you, or see <a href="https://metacpan.org/module/Types::CLike/" class="podlinkurl"
>https://metacpan.org/module/Types::CLike/</a>.</p>

<h1><a class='u'
name="SUPPORT"
>SUPPORT</a></h1>

<h2><a class='u'
name="Internet_Relay_Chat"
>Internet Relay Chat</a></h2>

<p>You can get live help by using IRC ( Internet Relay Chat ). If you don&#39;t know what IRC is, please read this excellent guide: <a href="http://en.wikipedia.org/wiki/Internet_Relay_Chat" class="podlinkurl"
>http://en.wikipedia.org/wiki/Internet_Relay_Chat</a>. Please be courteous and patient when talking to us, as we might be busy or sleeping! You can join those networks/channels and get help:</p>

<ul>
<li>irc.perl.org
<p>You can connect to the server at &#39;irc.perl.org&#39; and talk to this person for help: SineSwiper.</p>
</li>
</ul>

<h2><a class='u'
name="Bugs_/_Feature_Requests"
>Bugs / Feature Requests</a></h2>

<p>Please report any bugs or feature requests via <a href="https://github.com/SineSwiper/Types-CLike/issues" class="podlinkurl"
>https://github.com/SineSwiper/Types-CLike/issues</a>.</p>

<h1><a class='u'
name="AUTHOR"
>AUTHOR</a></h1>

<p>Brendan Byrd &#60;BBYRD@CPAN.org&#62;</p>

<h1><a class='u'
name="CONTRIBUTOR"
>CONTRIBUTOR</a></h1>

<p>Brendan Byrd &#60;bbyrd@cpan.org&#62;</p>

<h1><a class='u'
name="COPYRIGHT_AND_LICENSE"
>COPYRIGHT AND LICENSE</a></h1>

<p>This software is Copyright (c) 2013 by Brendan Byrd.</p>

<p>This is free software, licensed under:</p>

<pre>  The Artistic License 2.0 (GPL Compatible)</pre>

<!-- end doc -->

</body></html>