11 die "Can't import CSS::Declare into a scope when already compiling one that uses it"
13 my ($class, @args) = @_;
14 my $opts = shift(@args) if ref($args[0]) eq 'HASH';
15 my $target = $class->_find_target(0, $opts);
16 my $unex = $class->_export_tags_into($target);
17 $class->_install_unexporter($unex);
22 my ($class, $extra_levels, $opts) = @_;
23 return $opts->{into} if defined($opts->{into});
24 my $level = ($opts->{into_level} || 1) + $extra_levels;
25 return (caller($level))[0];
43 sub _export_tags_into {
44 my ($class, $into) = @_;
45 for my $property (@properties) {
46 my $property_name = $property;
47 $property_name =~ tr/_/-/;
49 *{"$into\::$property"} = sub ($) { return ($property_name => $_[0]) };
52 foreach my $property (@properties) {
54 delete ${"${into}::"}{$property}
60 sub _install_unexporter {
61 my ($class, $unex) = @_;
62 $^H |= 0x120000; # localize %^H
63 $^H{'CSS::Declare::Unex'} = bless($unex, 'CSS::Declare::Unex');
68 return join q{ }, gather {
69 while (my ($selector, $declarations) = splice(@css, 0, 2)) {
70 take "$selector "._generate_declarations($declarations)
75 sub _generate_declarations {
76 my $declarations = shift;
78 return '{'.join(q{;}, gather {
79 while (my ($property, $value) = splice(@{$declarations}, 0, 2)) {
80 take "$property:$value"
85 package CSS::Declare::Unex;
87 sub DESTROY { local $@; eval { $_[0]->(); 1 } || warn "ARGH: $@" }