Author image Masanori Ohgita
and 1 contributors


CSS::LESS - Compile LESS stylesheet files (.less) using lessc


  use CSS::LESS;
  # Compile a single LESS stylesheet
  my $less = CSS::LESS->new();
  my $css = $less->compile('a:link { color: lighten('#000000', 10%); }');
  print $css."\n";

  # Compile a LESS stylesheets with using @include syntax of LESS.
  $less = CSS::LESS->new( include_paths => ['/foo/include/'] );
  $css = $less->compile('@import (less) 'bar.less'; div { width: 100px; }');
  print $css."\n";

This module has released as an alpha version.



It must installed, because this module is wrapper of "lessc".

You can install "lessc" using "npm" (Node.js Package Manager).

  $ npm install -g less
  $ lessc -v
  lessc x.x.x (LESS Compiler) [JavaScript]


  $ git clone git://
  $ cpanm ./p5-CSS-LESS


new ( [%params] )

Create an instance of CSS::LESS.

%params :


Path of include .less files.

This paths will be used for the @include syntax of .less stylesheet.

Use case of example:

  # File-A of LESS stylesheet
  # This file will be set as content when calling a 'compile' method.
  @include (less) 'foo.less';

  # File-B of LESS stylesheet
  # This file was already saved to: /var/www/include/foo.less
  div {
    width: (100+200)px;

  # Example of script
  my less = CSS::LESS->new( include_paths => [ '/var/www/include/' ] )
  my $css = $less->compile( File-A ); # Let compile the File-A.
  print $css."\n"; # It includes the File-B, and will be compiled.

Compress a compiled style-sheet. It means removing some whitespaces using lessc. (default: 0)

Avaiable value: 1 or 0. This item is same as parameter of lessc.


Force evaluation of imports. (default: 0)

Avaiable value: 1 or 0. This item is same as parameter of lessc.


Re-write relative urls to the base LESS stylesheet. (default: undef)

Avaiable value: 1 or 0. This item is same as parameter of lessc.


Set rootpath for url rewriting in relative imports and urls. (default: undef)

This item is same as parameter of lessc.


Outputs filename and line numbers. (default: undef)

Avalable value: 'comments', 'mediaquery', 'both', undef.

This item is same as parameter of lessc.


Path of LESS compiler (default: 'lessc' on the PATH.)


Dry-run mode for debug. (default: 0)


When an errors accrued, don't die. (default: 0)


Path of save for temporally files. (default: '/tmp/'' or other temporally directory.)

compile ( $content [, %params] )

Parse a LESS (.less) stylesheet, and compile to CSS (.css) stylesheet.

In addition, If you would prefer to compile from a file, firstly, please read a file with using the "File::Slurp" module or open method as simply. Then, parse it with this 'compile' method.


Content of LESS (.less) stylesheet.


This item is optional. You can use parameters same as %params of new(...) method.

is_lessc_installed ( )

Check for lessc has installed.

last_error ()

Get a message of last error. (This method is useful only if 'dont_die' parameter is set when initialized an instance.)

SEE ALSO - Develop on GitHub. Your feedback is highly appreciated.

CSS::LESSp - LESS-parser by native perl implementation.



Copyright (C) 2013, Masanori Ohgita (

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.