File Coverage

blib/lib/Soar/Production.pm
Criterion Covered Total %
statement 32 32 100.0
branch 2 4 50.0
condition 1 3 33.3
subroutine 10 10 100.0
pod 4 4 100.0
total 49 53 92.4


line stmt bran cond sub pod time code
1             #
2             # This file is part of Soar-Production
3             #
4             # This software is copyright (c) 2012 by Nathan Glenn.
5             #
6             # This is free software; you can redistribute it and/or modify it under
7             # the same terms as the Perl 5 programming language system itself.
8             #
9             package Soar::Production;
10             # ABSTRACT: REPRESENT SOAR PRODUCTIONS
11 2     2   49064 use strict;
  2         5  
  2         101  
12 2     2   15 use warnings;
  2         4  
  2         69  
13              
14 2     2   24 use Carp;
  2         4  
  2         148  
15 2     2   1272 use Soar::Production::Parser;
  2         6  
  2         115  
16 2     2   62 use Data::Dumper;
  2         4  
  2         105  
17             use Exporter::Easy (
18 2         19 OK => [qw(prods_from prods_from_file)]
19 2     2   11 );
  2         4  
20              
21             our $VERSION = '0.03'; # VERSION
22              
23              
24              
25             my $parser = Soar::Production::Parser->new;
26              
27             #if run as a script, prints the name of every production in an input file.
28             unless(caller){
29             my $prods = prods_from_file( $ARGV[0] );
30             for my $prod (@$prods){
31             print $prod->name . "\n";
32             }
33             }
34              
35              
36             sub new {
37 1     1 1 15 my ($class, $text) = @_;
38 1         12 my $prod = bless $parser->parse_text($text), $class;
39 1         22313 return $prod;
40             }
41              
42             # sub as_text {
43             # my ($class) = @_;
44             # # return tree_to_text($class)
45             # }
46              
47              
48             sub name {
49 4     4 1 903 my ($prod, $name) = @_;
50             # print Dumper $prod;
51 4 50       15 $prod->{name} = $name
52             if($name);
53 4         21 return $prod->{name};
54             }
55              
56              
57             sub prods_from_file{
58 1     1 1 2 my ($file) = @_;
59 1         5 return prods_from( file => $file );
60             }
61              
62              
63             sub prods_from {## no critic (RequireArgUnpacking)
64 1     1 1 4 my (%args) = @_;
65 1 50 33     19 $args{text} or $args{file}
66             or croak 'Must specify parameter \'file\' or \'text\' to extract productions.';
67              
68 1         11 my $parses = $parser->productions(@_, parse => 1);
69 1         7 my @prods = map { bless $_ } @$parses; ## no critic(ProhibitOneArgBless)
  3         9  
70              
71 1         8 return \@prods;
72             }
73              
74             1;
75              
76             __END__