Categorizer/Document/SMART.pm untested

filter: Statementstmt 0.0% 0 / 17 Branchbran n/a Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 25 CC 1 SCAR 6.9
CC
1
Cov
0%
parse
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package AI::Categorizer::Document::SMART;
2  
3 use strict;
4 use AI::Categorizer::Document;
5 use base qw(AI::Categorizer::Document);
6  
7 sub parse {
8 my ($self, %args) = @_;
9
10 $args{content} =~ s{
11 ^(?:\.I)?\s+(\d+)\n # ID number - becomes document name
12 \.C\n
13 ([^\n]+)\n # Categories
14 \.T\n
15 (.+)\n+ # Title
16 \.W\n
17 }
18 {}sx
19
20 or die "Malformed record: $args{content}";
21
22 my ($id, $categories, $title) = ($1, $2, $3);
23  
24 $self->{name} = $id;
25 $self->{content} = { title => $title,
26 body => $args{content} };
27  
28 my @categories = $categories =~ m/(.*?)\s+\d+[\s;]*/g;
29 @categories = map AI::Categorizer::Category->by_name(name => $_), @categories;
30 $self->{categories} = \@categories;
31 }
32  
33 1;