lib/AI/MicroStructure/Object.pm

filter: Statementstmt 68.0% 17 / 25 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 71.4% 5 / 7 Podpod 0.0% 0 / 2 totaltotal 64.7% 22 / 34 CC 2 SCAR 8.6
CC
2
Cov
68%
decruft
6.0
TO_JSON
2.0
BEGIN
1.0
CRAP 2.4
« lib/AI/MicroStructure/Fitnes.pm ↑ Summary lib/AI/MicroStructure/Remember.pm »
1 #!/usr/bin/perl -W
2  
3  
4 package AI::MicroStructure::Object;
5  
6  
7 1 ▶ use Cache::Memcached::Fast;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 1 our $memd = new Cache::Memcached::Fast({
10 servers => [ { address => 'localhost:11211', weight => 2.5 }],
11 namespace => 'my:',
12 connect_timeout => 0.2,
13 io_timeout => 0.1,
14 close_on_error => 1,
15 compress_threshold => 100_000,
16 compress_ratio => 0.9,
17 max_failures => 1,
18 max_size => 512 * 1024,
19 });
20  
21  
22 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶use Digest::MD5 qw(md5_hex);
Subroutine BEGIN: called CC=1 SCAR=0.0
24 1 ▶use Data::Printer;
Subroutine BEGIN: called CC=1 SCAR=0.0
25 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 #use AnyEvent::Subprocess::Easy qw(qx_nonblock);
27 sub new {
28 my $pkg = shift;
29 my @tools = pop;
30 my $self = bless {}, $pkg;
31 $self->{tools} = shift @tools;
32 # p $self;
33 my $i = 0;
34  
35 $self->{md5} = md5_hex(@_);
36 $self->{name} = "@_";
37  
38 $self->{micro} = [split("\n",$self->check("@_","micrownet"))] ;
39 $self->{second}->{$_}=[split("\n",$self->check("$_","micrownet") )] for @{$self->{micro}};
40 # $self->{files}->{micro} = [split("\n",$self->check("@_","micro-index"))] ;
41 # $self->{files}->{second}->{$_}=[split("\n",$self->check("$_","micro-index") )] for @{$self->{micro}};
42 $self->{weight} = {};
43  
44 foreach(@{$self->{micro}}){
45  
46 foreach(@{$self->{second}->{$_}}){
47  
48 if($self->{weight}->{$_})
49 {
50 $self->{weight}->{$_}++;
51 }else{
52 $self->{weight}->{$_} = 1;
53 }
54 }
55 }
56  
57 foreach(keys %{$self->{weight}}){
58 delete $self->{weight}->{$_} unless($self->{weight}->{$_}>1);
59 }
60  
61  
62  
63 return $self;
64 }
65  
66 sub TO_JSON {
67 0 ▶ my $self = shift;
Subroutine TO_JSON: not called CC=1 SCAR=6.9
Pod undocumented
68 0 return { class => 'Object', data => { %$self } };
69 }
70  
71  
72 sub decruft {
73 0 ▶ my $self = shift;
Subroutine decruft: not called CC=2 SCAR=17.9
Pod undocumented
74 0 my($file) = @_;
75 0 my($cruftSet) = q{%§&|#[^+*( ]),'"; };
76 0 my $clean = $file;
77 0 $clean=~s/\Q$_//g for split("",$cruftSet);
78  
79 0 return $clean;
80 }
81  
82 sub tools {
83 my $self = shift;
84 $self->{tools} = \@_;
85  
86  
87 }
88 sub check {
89 my $self = shift;
90 my $name = shift;
91 my $prog = shift;
92 $name = $self->decruft($name);
93  
94 if(defined(my $ret = $memd->get(sprintf("%s_%s",$name,$prog)))){
95 return $ret;
96 }else{
97 my $ret = `$prog $name`;
98 $memd->set(sprintf("%s_%s",$name,$prog),$ret);
99 return $ret;
100 }
101 }
102  
103 sub name {
104  
105 my $self = shift;
106 return $self->{name};
107 }
108 1 1;
109  
110  
111 =head1 NAME
112  
113 AI::MicroStructure::Object
114  
115 =head1 DESCRIPTION
116  
117 Stack of ObjectContainers
118  
119 =head1 SYNOPSIS
120  
121 ~$ micro new world
122  
123 ~$ micro structures
124  
125 ~$ micro any 2
126  
127 ~$ micro drop world
128  
129 ~$ micro
130  
131 =head1 AUTHOR
132  
133 Hagen Geissler <santex@cpan.org>
134  
135 =head1 COPYRIGHT AND LICENCE
136  
137 Hagen Geissler <santex@cpan.org>
138  
139 =head1 SUPPORT AND DOCUMENTATION
140  
141 [sample using concepts](http://quantup.com)
142  
143 [PDF info on my works](https://github.com/santex)
144  
145  
146 =head1 SEE ALSO
147  
148 AI-MicroStructure
149  
150 =cut
« lib/AI/MicroStructure/Fitnes.pm ↑ Summary lib/AI/MicroStructure/Remember.pm »