| 1 | ############################################################################# | ||
| 2 | ## Name: Build.pm | ||
| 3 | ## Purpose: Build class for HPLOO classes. | ||
| 4 | ## Author: Graciliano M. P. | ||
| 5 | ## Modified by: | ||
| 6 | ## Created: 30/10/2004 | ||
| 7 | ## RCS-ID: | ||
| 8 | ## Copyright: (c) 2004 Graciliano M. P. | ||
| 9 | ## Licence: This program is free software; you can redistribute it and/or | ||
| 10 | ## modify it under the same terms as Perl itself | ||
| 11 | ############################################################################# | ||
| 12 | |||
| 13 | package Class::HPLOO::Build ; | ||
| 14 | |||
| 15 | use 5.006 ; | ||
| 16 | use strict qw(vars) ; | ||
| 17 | |||
| 18 | use vars qw($VERSION $SYNTAX @ISA) ; | ||
| 19 | |||
| 20 | $VERSION = '0.1'; | ||
| 21 | |||
| 22 | use Class::HPLOO qw(donothing) ; | ||
| 23 | |||
| 24 | ########### | ||
| 25 | # REQUIRE # | ||
| 26 | ########### | ||
| 27 | |||
| 28 | eval(q` require ePod ;`); | ||
| 29 | my $USE_EPOD = $@ ? 0 : 1 ; | ||
| 30 | |||
| 31 | ######### | ||
| 32 | # BUILD # | ||
| 33 | ######### | ||
| 34 | |||
| 35 | sub build { | ||
| 36 | my $ARGS_REF = ref $_[0] ? shift(@_) : [] ; | ||
| 37 | my @ARGV = @_ ; | ||
| 38 | |||
| 39 | ## HELP | ||
| 40 | |||
| 41 | if ( $ARGV[0] =~ /^-+h/i || !@ARGV ) { | ||
| 42 | my ($script) = ( $0 =~ /([^\\\/]+)$/s ); | ||
| 43 | |||
| 44 | print qq`____________________________________________________________________ | ||
| 45 | |||
| 46 | Class::HPLOO - $Class::HPLOO::VERSION | ||
| 47 | ____________________________________________________________________ | ||
| 48 | |||
| 49 | USAGE: | ||
| 50 | |||
| 51 | $script file.hploo file.pm | ||
| 52 | |||
| 53 | |||
| 54 | BUILD RECURSIVETY FROM A PATH: | ||
| 55 | |||
| 56 | $script -r ./ | ||
| 57 | |||
| 58 | ** Note that only .hploo files older than | ||
| 59 | it's .pm files will be built. | ||
| 60 | |||
| 61 | (C) Copyright 2000-2004, Graciliano M. P. <gmpassos\@cpan.org> | ||
| 62 | ____________________________________________________________________ | ||
| 63 | `; | ||
| 64 | |||
| 65 | return ; | ||
| 66 | } | ||
| 67 | |||
| 68 | if ( $ARGV[0] =~ /^-r$/i ) { | ||
| 69 | my $base = $ARGV[1] || '.' ; | ||
| 70 | |||
| 71 | my @files = scan_files($base) ; | ||
| 72 | |||
| 73 | foreach my $files_i ( @files ) { | ||
| 74 | my $pm_file = $files_i ; | ||
| 75 | $pm_file =~ s/\.hploo$/\.pm/i ; | ||
| 76 | |||
| 77 | if ( -s $pm_file ) { | ||
| 78 | my $hploo_md_time = (stat($files_i))[9] ; | ||
| 79 | my $pm_md_time = (stat($pm_file))[9] ; | ||
| 80 | if ( $pm_md_time >= $hploo_md_time ) { next ;} | ||
| 81 | } | ||
| 82 | |||
| 83 | build($files_i , $pm_file , 1) ; | ||
| 84 | } | ||
| 85 | |||
| 86 | return ; | ||
| 87 | } | ||
| 88 | |||
| 89 | ## CONVERT | ||
| 90 | |||
| 91 | my $EPOD = $USE_EPOD ? ePod->new( over_size => 4 ) : undef ; | ||
| 92 | |||
| 93 | my $hploo_file = shift(@ARGV) ; | ||
| 94 | my $pm_file = ($ARGV[0] =~ /\.pm$/i) ? shift(@ARGV) : $hploo_file ; | ||
| 95 | my $replace = @ARGV[-1] eq '1' ? 1 : undef ; | ||
| 96 | |||
| 97 | die("File $hploo_file need to have the extension .hploo!") if $hploo_file !~ /\.hploo$/i ; | ||
| 98 | |||
| 99 | die("Can't find file $hploo_file!") if !-e $hploo_file ; | ||
| 100 | |||
| 101 | $pm_file =~ s/\.hploo$/\.pm/i ; | ||
| 102 | |||
| 103 | die ("File $pm_file already exists! Can't replace it.") if ( !$replace && -s $pm_file ) ; | ||
| 104 | |||
| 105 | my %inc = %INC ; | ||
| 106 | |||
| 107 | my $code = Class::HPLOO::build_hploo($hploo_file , $pm_file , $$ARGS_REF[0]) ; | ||
| 108 | |||
| 109 | %INC = %inc ; | ||
| 110 | |||
| 111 | print "$hploo_file [OK] (converted to $pm_file).\n" ; | ||
| 112 | |||
| 113 | } | ||
| 114 | |||
| 115 | ############## | ||
| 116 | # SCAN_FILES # | ||
| 117 | ############## | ||
| 118 | |||
| 119 | sub scan_files { | ||
| 120 | my ( $dir ) = @_ ; | ||
| 121 | |||
| 122 | my @files ; | ||
| 123 | |||
| 124 | my @DIR = $dir ; | ||
| 125 | foreach my $DIR ( @DIR ) { | ||
| 126 | my $DH ; | ||
| 127 | opendir ($DH, $DIR); | ||
| 128 | |||
| 129 | while (my $filename = readdir $DH) { | ||
| 130 | if ($filename ne "\." && $filename ne "\.\.") { | ||
| 131 | my $file = "$DIR/$filename" ; | ||
| 132 | if (-d $file) { push(@DIR , $file) ;} | ||
| 133 | elsif ( $filename =~ /\.hploo$/i ) { | ||
| 134 | push(@files , $file) ; | ||
| 135 | } | ||
| 136 | } | ||
| 137 | } | ||
| 138 | |||
| 139 | closedir ($DH) ; | ||
| 140 | } | ||
| 141 | |||
| 142 | return( @files ) ; | ||
| 143 | } | ||
| 144 | |||
| 145 | ####### | ||
| 146 | # END # | ||
| 147 | ####### | ||
| 148 | |||
| 149 | 1; | ||
| 150 | |||
| 151 |