| 1 | package MYDan::Diagnosis; | ||
| 2 | use warnings; | ||
| 3 | use strict; | ||
| 4 | |||
| 5 | sub new | ||
| 6 | { | ||
| 7 | my ( $class, %self ) = @_; | ||
| 8 | map{ | ||
| 9 | die "$_ defined error" unless $self{$_} && $self{$_} =~ /^[a-zA-Z0-9_:\-]+$/ | ||
| 10 | }qw( os arch ); | ||
| 11 | bless \%self, ref $class || $class; | ||
| 12 | } | ||
| 13 | |||
| 14 | sub run | ||
| 15 | { | ||
| 16 | my ( $this, $path, $x ) = splice @_, 0, 2; | ||
| 17 | die "path undef" unless defined $path; | ||
| 18 | |||
| 19 | map { $x += -f $_ ? $this->do( $_ ) : $this->run( $_ ); }glob "$path/*"; | ||
| 20 | return $x; | ||
| 21 | } | ||
| 22 | |||
| 23 | sub do | ||
| 24 | { | ||
| 25 | my ( $this, $path ) = @_; | ||
| 26 | |||
| 27 | die "path undef" unless defined $path; | ||
| 28 | |||
| 29 | my $title = $path; $title =~ s#.*/plugin/code/##; | ||
| 30 | print "=" x 75, "\n$title\n"; | ||
| 31 | |||
| 32 | my $temp = $path; | ||
| 33 | $temp =~ s#/plugin/code/#/plugin/$this->{os}/$this->{arch}/code/#; | ||
| 34 | |||
| 35 | my $code = do ( -f $temp ? $temp : $path ); | ||
| 36 | die "load code: $path fail" unless $code && ref $code eq 'CODE'; | ||
| 37 | &$code(); | ||
| 38 | } | ||
| 39 | |||
| 40 | 1; |