FTN::Bit_flags - Object-oriented module for working with bit flags.
version 20160324
use Log::Log4perl (); use FTN::Bit_flags (); Log::Log4perl -> easy_init( $Log::Log4perl::INFO ); # let's work with message attributes my $attribute = FTN::Bit_flags -> new( { abbr => 'PVT', name => 'PRIVATE', }, { abbr => 'CRA', name => 'CRASH', }, { abbr => 'RCV', name => 'READ', }, { abbr => 'SNT', name => 'SENT', }, { abbr => 'FIL', name => 'FILEATT', }, { name => 'TRANSIT', }, { name => 'ORPHAN', }, { abbr => 'K/S', name => 'KILL', }, { name => 'LOCAL', }, { abbr => 'HLD', name => 'HOLD', }, { abbr => 'XX2', }, { abbr => 'FRQ', abbr => 'FREQ', }, { abbr => 'RRQ', name => 'Receipt REQ', }, { abbr => 'CPT', }, { abbr => 'ARQ', }, { abbr => 'URQ', }, ); $attribute -> set_from_number( get_attribute_from_message() ); print join ', ', $attribute -> list_of_set; print 'this is a private message' if $attribute -> is_set( 'PVT' ); # make sure it is local and its flavour is crash $attribute -> set( 'LOCAL', 'CRASH' ); # though we don't need it to be killed after sent $attribute -> clear( 'K/S' ); update_message_attribute_field( $attribute -> as_number ); $attribute -> set_from_number( get_attribute_from_another_message() ); # work with new attribute value the same way as above
FTN::Bit_flags module is for working with bit flags commonly used in FTN messages.
my $bit_flags = FTN::Bit_flags -> new( { abbr => 'flag 1' }, { name => 'second lowest bit' }, { abbr => 'flag 2', name => 'flag numeric mask is 4' } );
Parameters are hash references representing bit in order from low to high. At least one parameter is required. Each hash reference should have 'abbr' and/or 'name' fields. Dies in case of error.
After object describing all possible fields is created we can use it to work with already defined value:
$bit_flags -> set_from_number( 3 );
We can clear all bitfields (setting numeric value to 0):
$bit_flags -> clear_all;
To set one (or more) fields:
$bit_flags -> set( 'second lowest bit', 'flag 2' );
If you have equal 'abbr' for one field and 'name' for another field, then 'abbr' has higher priority here.
To clear one (or more) fields:
$bit_flags -> clear( 'second lowest bit' );
To check if some field is set:
print 'it is set' if $bit_flags -> is_set( 'second lowest bit' );
To get numeric value after you set or cleared some flags:
print $bit_flags -> as_number;
To get list of set flags:
print join ' ', $bit_flags -> list_of_set;
By default it tries to return 'abbr' field value for each set bit and if there is none, then return 'name' field value. If 'name' field is preferable, pass optional parameter 'name'.
print join ' ', $bit_flags -> list_of_set( 'name' );
Valery Kalesnik, <valkoles at gmail.com>
<valkoles at gmail.com>
Please report any bugs or feature requests to bug-ftn-bit_flags at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=FTN-Bit_flags. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-ftn-bit_flags at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc FTN::Bit_flags
To install FTN::Bit_flags, copy and paste the appropriate command in to your terminal.
cpanm
cpanm FTN::Bit_flags
CPAN shell
perl -MCPAN -e shell install FTN::Bit_flags
For more information on module installation, please visit the detailed CPAN module installation guide.