• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

DrHyde / perl-modules-String-Binary-Interpolation / 5163200322

pending completion
5163200322

Pull #8

github

web-flow
Merge 5683e3ddf into 2488ab9eb
Pull Request #8: Bump cross-platform-actions/action from 0.13.0 to 0.14.0

6 of 6 relevant lines covered (100.0%)

43.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/lib/String/Binary/Interpolation.pm
1
package String::Binary::Interpolation;
2

3
use strict;
1✔
4
use warnings;
1✔
5

6
# Yuck, semver. I give in, the stupid cult that doesn't understand
7
# what the *number* bit of *version number* means has won.
8
our $VERSION = '1.0.0';
9

10
sub import {
11
    my $victim = (caller(0))[0];
1✔
12
    foreach my $byte (0 .. 255) {
1✔
13
        no strict 'refs';
1✔
14
        *{sprintf('%s::b%08b', $victim, $byte)} = \chr($byte);
256✔
15
    }
16
}
17

18
1;
19

20
=head1 NAME
21

22
String::Binary::Interpolation
23

24
=head1 DESCRIPTION
25

26
Make it easier to interpolate binary bytes into a string
27

28
=head1 SYNOPSIS
29

30
Where you would previously have had to write something like this ...
31

32
    my $binary = "ABC@{[chr(0b01000100)]}E"
33

34
or ...
35

36
    my $binary = 'ABC'.chr(0b01000100).'E';
37

38
to interpolate some random byte into a string you can now do this ...
39

40
    use String::Binary::Interpolation;
41

42
    my $binary = "ABC${b01000100}E";
43

44
which I think you'll agree is much easier to read.
45

46
=head1 BUT WHY!?!?!?
47

48
Bit-fields, dear reader. If you are writing data to a binary file, and that
49
file contains bytes (or even longer words) which are bit-fields, it is easier
50
to have the bits of the bit-field right there in your string instead of having
51
to glue the string together from various parts, and it's far easier to read
52
than the frankly evil hack of embedding an array-ref.
53

54
=head1 OK, SO WHAT DOES IT DO?
55

56
When you C<use> the module all it does is create a bunch of varliables in
57
your namespace. They are named from C<$b00000000> to C<$b11111111> and their
58
values are the corresponding characters. NB that when writing files containing
59
characters with the high-bit set you need to be careful that you read and write
60
B<bytes> and not some unicode jibber-jabber.
61

62
=head1 SOURCE CODE REPOSITORY
63

64
L<https://github.com/DrHyde/perl-modules-String-Binary-Interpolation>
65

66
=head1 BUGS
67

68
Bug reports and requests for extra features should be made on Github.
69

70
=head1 AUTHOR
71

72
David Cantrell E<lt>david@cantrell.org.ukE<gt>
73

74
=head1 COPYRIGHT and LICENCE
75

76
Copyright (c) 2020 David Cantrell. This program is free software; you can
77
redistribute it and/or modify it under the terms of the Artistic Licence
78
or the GNU General Public Licence version 2, the full text of which is
79
included in this distribution, in the files ARTISTIC.txt and GPL2.txt.
80

81
=head1 SEE ALSO
82

83
L<perlop>'s section on quote and quote-like operators
84

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc