| 1 | 1 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 1 | ▶ | use warnings FATAL => 'all'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | package MarpaX::Java::ClassFile; | ||||||||||
| 5 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | |||||||||||
| 7 | 1 | ▶ | use Types::Standard qw/Str InstanceOf/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 8 | |||||||||||
| 9 | # ABSTRACT: Java .class parsing | ||||||||||
| 10 | |||||||||||
| 11 | our $VERSION = '0.008'; # VERSION | ||||||||||
| 12 | |||||||||||
| 13 | our $AUTHORITY = 'cpan:JDDPAUSE'; # AUTHORITY | ||||||||||
| 14 | |||||||||||
| 15 | has filename => ( is => 'ro', isa => Str, required => 1); | ||||||||||
| 16 | has ast => ( is => 'ro', isa => InstanceOf['MarpaX::Java::ClassFile::Struct::ClassFile'], lazy => 1, builder => 1); | ||||||||||
| 17 | |||||||||||
| 18 | |||||||||||
| 19 | 1 | ▶ | use Carp qw/croak/; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 20 | require MarpaX::Java::ClassFile::BNF::ClassFile; | ||||||||||
| 21 | require MarpaX::Java::ClassFile::Struct::ClassFile; | ||||||||||
| 22 | |||||||||||
| 23 | sub _build_ast { | ||||||||||
| 24 | 0 | ▶ | my ($self) = @_; | ||||||||
|
Subroutine
_build_ast: not called CC=4 SCAR=30.0
| |||||||||||
| 25 | |||||||||||
| 26 | 0 | $self->log->tracef('Opening %s', $self->filename); | |||||||||
| 27 | 0 | ▶ | open(my $fh, '<', $self->filename) || do { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 28 | 0 | $self->log->fatalf('Cannot open %s, %s', $self->filename, $!); | |||||||||
| 29 | 0 | croak "Cannot open " . $self->filename . ", $!" | |||||||||
| 30 | }; | ||||||||||
| 31 | |||||||||||
| 32 | 0 | $self->log->tracef('Setting %s in binary mode', $self->filename); | |||||||||
| 33 | 0 | ▶ | binmode($fh) || do { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | 0 | $self->log->fatalf('Failed to set binary mode on %s, %s', $self->filename, $!); | |||||||||
| 35 | 0 | croak "Failed to set binary mode on " . $self->filename . ", $!" | |||||||||
| 36 | }; | ||||||||||
| 37 | |||||||||||
| 38 | 0 | $self->log->tracef('Reading %s', $self->filename); | |||||||||
| 39 | 0 | my $input = do { local $/; <$fh>}; | |||||||||
| 40 | |||||||||||
| 41 | 0 | $self->log->tracef('Closing %s', $self->filename); | |||||||||
| 42 | 0 | ▶ | close($fh) || do { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | 0 | $self->log->warnf('Failed to close %s, %s', $self->filename, $!); | |||||||||
| 44 | 0 | croak "Failed to close " . $self->filename . ", $!" | |||||||||
| 45 | }; | ||||||||||
| 46 | |||||||||||
| 47 | 0 | $self->log->debugf('Parsing %s', $self->filename); | |||||||||
| 48 | 0 | MarpaX::Java::ClassFile::BNF::ClassFile->new(inputRef => \$input, log => $self->log)->ast | |||||||||
| 49 | } | ||||||||||
| 50 | |||||||||||
| 51 | with 'MooX::Log::Any'; | ||||||||||
| 52 | |||||||||||
| 53 | 1; | ||||||||||
| 54 | |||||||||||
| 55 | __END__ | ||||||||||
| 56 | |||||||||||
| 57 | =pod | ||||||||||
| 58 | |||||||||||
| 59 | =encoding UTF-8 | ||||||||||
| 60 | |||||||||||
| 61 | =head1 NAME | ||||||||||
| 62 | |||||||||||
| 63 | MarpaX::Java::ClassFile - Java .class parsing | ||||||||||
| 64 | |||||||||||
| 65 | =head1 VERSION | ||||||||||
| 66 | |||||||||||
| 67 | version 0.008 | ||||||||||
| 68 | |||||||||||
| 69 | =head1 SYNOPSIS | ||||||||||
| 70 | |||||||||||
| 71 | use MarpaX::Java::ClassFile; | ||||||||||
| 72 | |||||||||||
| 73 | my $classFilename = shift || 'defaultFilename.class'; | ||||||||||
| 74 | my $o = MarpaX::Java::ClassFile->new(filename => $classFilename); | ||||||||||
| 75 | my $ast = $o->ast; | ||||||||||
| 76 | print "Javap-like output is using overloaded stringification: $ast\n"; | ||||||||||
| 77 | |||||||||||
| 78 | =head1 DESCRIPTION | ||||||||||
| 79 | |||||||||||
| 80 | This module provide and manage an AST of an Java .class file, as per Java Virtual Machine Specification SE 8 Edition. | ||||||||||
| 81 | |||||||||||
| 82 | =head1 SUBROUTINES/METHODS | ||||||||||
| 83 | |||||||||||
| 84 | =head2 new($class, %options --> InstanceOf['MarpaX::Java::ClassFile']) | ||||||||||
| 85 | |||||||||||
| 86 | Instantiate a new object, named $self later in this document. Takes as parameter a hash of options that can be: | ||||||||||
| 87 | |||||||||||
| 88 | =over | ||||||||||
| 89 | |||||||||||
| 90 | =item Str filename | ||||||||||
| 91 | |||||||||||
| 92 | Location of the .class file on your filesystem. This option is required. | ||||||||||
| 93 | |||||||||||
| 94 | =back | ||||||||||
| 95 | |||||||||||
| 96 | =head2 ast($self --> InstanceOf['MarpaX::Java::ClassFile::Struct::ClassFile']) | ||||||||||
| 97 | |||||||||||
| 98 | Returns the parse result, as an instance of L<MarpaX::Java::ClassFile::Struct::ClassFile>. | ||||||||||
| 99 | |||||||||||
| 100 | =head1 SEE ALSO | ||||||||||
| 101 | |||||||||||
| 102 | L<Marpa::R2> | ||||||||||
| 103 | |||||||||||
| 104 | L<The Java Virtual Machine Specification, Java SE 8 Edition, Chapter 4: The class File Format|https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html> | ||||||||||
| 105 | |||||||||||
| 106 | =head1 AUTHOR | ||||||||||
| 107 | |||||||||||
| 108 | Jean-Damien Durand <jeandamiendurand@free.fr> | ||||||||||
| 109 | |||||||||||
| 110 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 111 | |||||||||||
| 112 | This software is copyright (c) 2016 by Jean-Damien Durand. | ||||||||||
| 113 | |||||||||||
| 114 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 115 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 116 | |||||||||||
| 117 | =cut | ||||||||||