Clang-CastXML
view release on metacpan or search on metacpan
lib/Clang/CastXML.pm view on Meta::CPAN
package Clang::CastXML;
use Moo;
use 5.022;
use experimental qw( signatures );
use Ref::Util qw( is_blessed_ref is_ref );
use Clang::CastXML::Container;
use Path::Tiny ();
use Clang::CastXML::Exception::UsageException;
use Clang::CastXML::Exception::ProcessException::IntrospectException;
# ABSTRACT: C-family abstract syntax tree output tool
our $VERSION = '0.02'; # VERSION
has wrapper => (
is => 'ro',
lazy => 1,
default => sub {
require Clang::CastXML::Wrapper;
Clang::CastXML::Wrapper->new;
},
);
sub introspect ($self, $source, $dest=undef)
{
if(is_blessed_ref $source && $source->isa('Path::Tiny'))
{
# nothing to do
}
elsif(!is_ref $source && defined $source)
{
my $content = $source;
$source = Path::Tiny->tempfile(
TEMPLATE => 'castxml-XXXXXX',
SUFFIX => '.C',
);
$source->spew_utf8($content);
}
else
{
Clang::CastXML::Exception::UsageException->throw(
diagnostic => "Source should be either a Path::Tiny instance or string containing the C source",
);
}
$dest //= Path::Tiny->tempfile(
TEMPLATE => 'castxml-XXXXXX',
SUFFIX => '.xml',
);
unless(is_ref $dest && $dest->isa('Path::Tiny'))
{
Clang::CastXML::Exception::UsageException->throw(
diagnostic => "Destination should be a Path::Tiny object",
);
}
my $result = $self->wrapper->raw("--castxml-output=1", "-o" => "$dest", "$source");
if($result->is_success)
{
return Clang::CastXML::Container->new(
result => $result,
source => $source,
( run in 3.333 seconds using v1.01-cache-2.11-cpan-d8267643d1d )