NAME
Parser::FIT - A parser for garmin FIT (Flexible and Interoperable Data Transfer) files
SYNOPSIS
use Parser::FIT;
my $recordCount = 0;
my $parser = Parser::FIT->new(on => {
record => sub { $recordMsg = shift; $recordCount++; }
});
$parser->parse("some/file.fit");
print "The file contained $recordCount records.";
ALPHA STATUS
The module is in an early alpha status. APIs may change. Parse results may be wrong.
Additionally i will probably not implement the full set of FIT messages. I started the module for my personal needs to be able to parse FIT files from my garmin bike computer. So results for e.g. a triathlon multisport watch may varry greatly!
But this module is free and open source: Feel free to contribute code, example data, etc!
METHODS
new
Create a new Parser::FIT object.
Parameters:
on
Register and deregister handlers for a parser.
$parser->on(record => sub { });
Registering and already existing handler overwrites the old one.
$parser->on(session => sub { say "foo" });
$parser->on(session => sub { say "bar" }); # Overwrites the previous handler
Registering a falsy value for a message type will deregister the handler:
$parser->on(session => undef);
There is currently no check, if the provided message name actually represents an existing one from the FIT specs.
Additionally there is one special message name: _any
. Which can be used to receive just every message encountered by the parser:
$parser->on(_any => sub {
my $msgType = shift;
my $msgData = shift;
print "Saw a messafe of type $msgType";
});
The on
method can also be called from inside a handler callback in order to de-/register handlers based on the stream of events
# Count the number of records per lap
my $lapCount = 0;
my $lapResults = [];
$parser->on("lap" => sub {
my $lapMsg = shift;
my $lapCount++;
$parser->on("record" => {
$lapResults[$lapCount]++;
});
});
AUTHOR
This module was created by Sven Eppler <ghandi@cpan.org>
COPYRIGHT AND LICENSE
Copyright (C) 2018-2022 by Sven Eppler
This program is free software, you can redistribute it and/or modify it under the terms of the Artistic License version 2.0.