CSS::Sass::Type - Data Types for custom Sass Functions
Sass_Values
You can use maps and lists like normal hash or array references. Lists can have two different separators used for stringification. This is detected by checking if the object is derived from CSS::Sass::Type::List::Space. The default is a comma separated list, which you get by instantiating CSS::Sass::Type::List or CSS::Sass::Type::List::Comma.
maps
lists
hash
array
CSS::Sass::Type::List::Space
CSS::Sass::Type::List
CSS::Sass::Type::List::Comma
my $null = CSS::Sass::Type->new(undef); # => 'null' my $number = CSS::Sass::Type->new(42.35); # => 42.35 my $string = CSS::Sass::Type->new("foobar"); # => 'foobar' my $map = CSS::Sass::Type->new({ key => "foobar" }); # 'key: foobar' my $list = CSS::Sass::Type->new([ "foo", 42, "bar" ]); # 'foo, 42, bar' my $space = CSS::Sass::Type::List::Space->new("foo", "bar"); # 'foo bar' my $comma = CSS::Sass::Type::List::Comma->new("foo", "bar"); # 'foo, bar'
You can also return these native perl types from custom functions. They will automatically be upgraded to real CSS::Sass::Type objects. All types overload the stringify and eq operators (so far).
CSS::Sass::Type
stringify
eq
Acts as a base class for all other types and is mainly an abstract class. It only implements a generic constructor, which accepts native perl data types (undef, numbers, strings, array-refs and hash-refs) and CSS::Sass::Type objects.
my $null = CSS::Sass::Type::Null->new; my $string = "$null"; # eq 'null' my $value = $null->value; # == undef
my $bool = CSS::Sass::Type::Boolean->new(42); my $string = "$bool"; # eq 'true' my $value = $bool->value; # == 1
my $number = CSS::Sass::Type::Boolean->new(42, 'px'); my $string = "$number"; # eq '42px' my $value = $number->value; # == 42 my $unit = $number->unit; # eq 'px'
my $string = CSS::Sass::Type->new("foo bar"); # => "foo bar" my $quoted = "$string"; # eq '"foo bar"' my $unquoted = $string->value; # eq 'foo bar'
my $color = CSS::Sass::Type::Color->new(64, 128, 32, 0.25); my $string = "$color"; # eq 'rgba(64, 128, 32, 0.25)' my $r = $color->r; # == 64 my $g = $color->g; # == 128 my $b = $color->b; # == 32 my $a = $color->a; # == 0.25
my $map = CSS::Sass::Type::Map->new(key => 'value'); my $string = "$map"; # eq 'key: value' my $value = $map->{'key'}; # eq 'value'
my $list = CSS::Sass::Type::List::Comma->new('foo', 'bar'); my $string = "$list"; # eq 'foo, bar' my $value = $list->[0]; # eq 'foo'
my $list = CSS::Sass::Type::List::Space->new('foo', 'bar'); my $string = "$list"; # eq 'foo bar' my $value = $list->[-1]; # eq 'bar'
CSS::Sass
David Caldwell <david@porkrind.org> Marcel Greter <perl-libsass@ocbnet.ch>
Copyright (C) 2013 by David Caldwell Copyright (C) 2014 by Marcel Greter
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.12.4 or, at your option, any later version of Perl 5 you may have available.
To install CSS::Sass, copy and paste the appropriate command in to your terminal.
cpanm
cpanm CSS::Sass
CPAN shell
perl -MCPAN -e shell install CSS::Sass
For more information on module installation, please visit the detailed CPAN module installation guide.