App-colourhexdump

 view release on metacpan or  search on metacpan

lib/App/colourhexdump/Formatter.pm  view on Meta::CPAN

use 5.006;    # our
use strict;
use warnings;

package App::colourhexdump::Formatter;

our $VERSION = '1.000003';

# ABSTRACT: Colour-Highlight lines of data as hex.

our $AUTHORITY = 'cpan:KENTNL'; # AUTHORITY

use Moose qw( has );
use String::RewritePrefix;
use Module::Runtime qw( require_module );
use Term::ANSIColor 3.00 qw( colorstrip );

use namespace::autoclean;

has colour_profile => (
  does       => 'App::colourhexdump::ColourProfile',
  is         => 'rw',
  lazy_build => 1,
  init_arg   => undef,
);

has real_colour_profile_class => (
  isa        => 'Str',
  is         => 'rw',
  lazy_build => 1,
  init_arg   => undef,
);

has colour_profile_class => (
  isa      => 'Str',
  is       => 'rw',
  init_arg => 'colour_profile',
  default  => 'DefaultColourProfile',
);

has row_length => (
  isa     => 'Int',
  is      => 'ro',
  default => 32,
);

has chunk_length => (
  isa     => 'Int',
  is      => 'rw',
  default => 4,
);

has hex_row_length => (
  isa        => 'Int',
  is         => 'rw',
  lazy_build => 1,
  init_arg   => undef,
);

__PACKAGE__->meta->make_immutable;
no Moose;

sub _build_hex_row_length {
  my $self = shift;

  # Each byte takes 2 bytes to print.
  #
  if ( $self->chunk_length > $self->row_length ) {
    $self->chunk_length( $self->row_length );
  }
  my $real_chunk_length = $self->chunk_length * 2;

  my $chunks     = int( $self->row_length / $self->chunk_length );
  my $extrachunk = 0;

  if ( ( $chunks * $self->chunk_length ) < $self->row_length ) {
    $extrachunk = $self->row_length - ( $chunks * $self->chunk_length );
  }



( run in 0.661 second using v1.01-cache-2.11-cpan-ceb78f64989 )