Analizo

 view release on metacpan or  search on metacpan

lib/Analizo/Extractor/Doxyparse.pm  view on Meta::CPAN

package Analizo::Extractor::Doxyparse;

use strict;
use warnings;

use parent qw(Analizo::Extractor);

use File::Temp qw/ tempfile /;
use Cwd;
use YAML::XS;
use File::Spec::Functions qw/ tmpdir /;

sub new {
  my ($package, @options) = @_;
  return bless { files => [], @options }, $package;
}

sub _add_file {
  my ($self, $file) = @_;
  push(@{$self->{files}}, $file);
}

sub _cpp_hack {
  my ($self, $module) = @_;
  my $current = $self->current_file;
  if (defined($current) && $current =~ /^(.*)\.(h|hpp)$/) {
    my $prefix = $1;
    # look for a previously added .cpp/.cc/etc
    my @implementations = grep { /^$prefix\.(cpp|cxx|cc)$/ } @{$self->{files}};
    foreach my $file (@implementations) {
      $self->model->declare_module($module, $file);
    }
  }
  if (defined($current) && $current =~ /^(.*)\.(cpp|cxx|cc)$/) {
    my $prefix = $1;
    # look for a previously added .h/.hpp/etc
    my @implementations = grep { /^$prefix\.(h|hpp)$/ } @{$self->{files}};
    foreach my $file (@implementations) {
      $self->model->declare_module($module, $file);
    }
  }
}

sub feed {
  my ($self, $doxyparse_output, $line) = @_;
  my $yaml = undef;
  eval { $yaml = Load($doxyparse_output) };
  if ($@) {
    die $!;
  }
  foreach my $full_filename (sort keys %$yaml) {

    # current file declaration
    my $file = _strip_current_directory($full_filename);
    $self->current_file($file);
    $self->_add_file($file);

    # current module declaration
    foreach my $module (keys %{$yaml->{$full_filename}}) {
      my $modulename = _file_to_module($module);
      next if defined $yaml->{$full_filename}->{$module} && ref($yaml->{$full_filename}->{$module}) ne 'HASH';

      $self->current_module($modulename);
      $self->_cpp_hack($modulename);

      # inheritance
      if (defined $yaml->{$full_filename}->{$module}->{inherits}) {
        if (ref $yaml->{$full_filename}->{$module}->{inherits} eq 'ARRAY') {
          foreach my $inherits (@{ $yaml->{$full_filename}->{$module}->{inherits} }) {
            $self->model->add_inheritance($self->current_module, $inherits);
          }
        }
        else {
          my $inherits = $yaml->{$full_filename}->{$module}->{inherits};
          $self->model->add_inheritance($self->current_module, $inherits);



( run in 1.542 second using v1.01-cache-2.11-cpan-39bf76dae61 )