<commit_before>package Net::IPMI::PP::Packet;
use strict;
use warnings;
use Carp qw(croak confess);

my %len = (c => 1, C => 1, N => 4);

sub unpack {
  my ($class, $data) = @_;
  confess "Insufficient arguments" unless defined $data;

  my $self = bless {}, $class;
  my $fields = $self->fields;
  confess "Missing `fields' structure" unless defined $fields;

  my $pos = 0;
  for my $fieldspec (@$fields) {
    my $name = $fieldspec->{name};
    my $format = $fieldspec->{format};
    my $value = unpack $fieldspec->{format}, substr($data, $pos);
    croak "Invalid packet: could not decode $name"
      unless defined $value;
    $pos += $len{$fieldspec->{format}};
    $self->{header}{$name} = $self->constant($name, $value);
  }<commit_msg>Format string can contain a count (regression)<commit_after>package Net::IPMI::PP::Packet;
use strict;
use warnings;
use Carp qw(croak confess);

my %len = (c => 1, C => 1, N => 4);

sub unpack {
  my ($class, $data) = @_;
  confess "Insufficient arguments" unless defined $data;

  my $self = bless {}, $class;
  my $fields = $self->fields;
  confess "Missing `fields' structure" unless defined $fields;

  my $pos = 0;
  for my $fieldspec (@$fields) {
    my $name = $fieldspec->{name};
    my ($format, $count) = ($fieldspec->{format} =~ /^(\D+)(\d+)?$/);
    $count = 1 unless defined $count;
    my $value = unpack $fieldspec->{format}, substr($data, $pos);
    croak "Invalid packet: could not decode $name"
      unless defined $value;
    $pos += ($len{$format} * $count);
    $self->{header}{$name} = $self->constant($name, $value);
  }
{'fraction_non_alphanumeric': 0.18805031446540882, 'fraction_numerical': 0.005660377358490566, 'mean_word_length': 3.8654434250764527, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 22, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1276461', 'n_tokens_mistral': 558, 'n_tokens_neox': 538, 'n_words': 168}