Rex-Apache-Deploy

 view release on metacpan or  search on metacpan

lib/Rex/Apache/Build.pm  view on Meta::CPAN

sub build {
  my ( $name, %option ) = @_;

  unless ($name) {
    $name = basename( getcwd() );
  }

  if ( !%option ) {
    if ( Rex::Config->get("package_option") ) {
      %option = %{ Rex::Config->get("package_option") };
    }
  }

  if ( !exists $option{version} ) {
    $option{version} = &$APP_VERSION();
  }

  my $old_dir = getcwd();

  my $type = $option{type} || "tgz";

  my $klass = "Rex::Apache::Build::$type";
  eval "use $klass";
  if ($@) {
    die("Can't find build class for type: $type");
  }

  Rex::Logger::debug("Using Buildclass: $klass");
  $option{name} = $name;
  my $build = $klass->new(%option);

  $build->build;

  chdir($old_dir);
}

=item get_version_from($file, $regexp)

Get the version out of a file.

=cut

sub get_version_from {
  my ( $file, $regex ) = @_;

  if ( ref($file) eq "CODE" ) {
    $APP_VERSION = $file;
    return;
  }

  $APP_VERSION = sub {

    unless ( -f $file ) {
      Rex::Logger::info( "Version file not found ($file). Current Path: "
          . getcwd()
          . ". Using current time." );
      return "" . time;
    }

    my ($version) =
      grep { $_ = $1 if $_ =~ $regex; } eval { local (@ARGV) = ($file); <>; };

    return $version;

  };
}

sub get_version {
  return &$APP_VERSION();
}

=item sprocketize($path_to_js_files, %option)

This function calls the sprocketize command with the given options.

 task "build", sub {
   sprocketize "app/javascript/*.js",
            include   => [qw|app/javascripts vendor/sprockets/prototype/src|],
            asset_root => "public/js",
            out      => "public/js/sprockets.js";

   # to include more use an arrayRef
   sprocketize ["app/javascript/*.js", "app/javascript/po/*.js"],
            include   => [qw|app/javascripts vendor/sprockets/prototype/src|],
            asset_root => "public/js",
            out      => "public/js/sprockets.js";

   # if called without parameters

   sprocketize;

   # it will use the following defaults:
   # - javascript (sprockets) in assets/javascripts/*.js
   # - include  assets/javascripts
   # - asset_root public
   # - out public/${name_of_directory_where_Rexfile_lives}.js
 };

=cut

sub sprocketize {
  my ( $files, %option ) = @_;

  my $dirname = basename( getcwd() );

  unless ($sprocketize_path) {
    $sprocketize_path = "sprocketize";
  }

  unless ($files) {
    $files = ["assets/javascripts/*.js"];
  }

  if ( !exists $option{out} ) {
    $option{out} = "public/$dirname.js";
  }

  if ( !exists $option{asset_root} ) {
    $option{asset_root} = "public";
  }



( run in 1.123 second using v1.01-cache-2.11-cpan-5c0b1e786e0 )