File: prepare_dist

package info (click to toggle)
libmail-imapclient-perl 3.42-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,548 kB
  • sloc: perl: 20,776; makefile: 23
file content (43 lines) | stat: -rwxr-xr-x 922 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/perl

use strict;
use warnings;

use File::Copy qw/move/;
use Parse::RecDescent 1.94;

sub read_file {
    my $file = shift;
    local ( $/, *FH );
    open( FH, $file ) or return undef;
    return <FH>;
}

build_parser(
    'lib/Mail/IMAPClient/BodyStructure/Parse.grammar',
    'Mail::IMAPClient::BodyStructure::Parse'
);

build_parser( 'lib/Mail/IMAPClient/Thread.grammar',
    'Mail::IMAPClient::Thread' );

sub build_parser {
    my ( $grammarfn, $package ) = @_;

    print("* building $package\n");

    my $grammar = read_file($grammarfn)
      or die("cannot read grammar from $grammarfn: $!\n");

    Parse::RecDescent->Precompile( $grammar, $package );

    # clumpsy output by Parse::RecDescent
    my $outfn = $package . '.pm';
    $outfn =~ s/.*\:\://;

    my $realfn = $grammarfn;
    $realfn =~ s/\.\w+$/.pm/;

    move( $outfn, $realfn )
      or die("cannot move $outfn to $realfn: $!\n");
}