File Coverage

blib/lib/HTML/Element/Replacer.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1             package HTML::Element::Replacer;
2             # ABSTRACT: Simplify the HTML::Element clone() - push_content() ritual
3 2     2   89222 use HTML::TreeBuilder;
  2         48084  
  2         41  
4 2     2   1375 use HTML::Element::Library;
  0            
  0            
5              
6             use Moose;
7              
8             has 'tree' => ( is => 'rw', required => 1 ) ;
9             has 'elem' => ( is => 'rw', lazy => 1, default => sub { $_[0]->tree->look_down(@{$_[0]->look_down}) } ) ;
10             has 'elem_clone' => ( is => 'rw' ) ;
11             has 'look_down' => ( is => 'rw', required => 1 ) ;
12             has 'replacements' => ( is => 'rw', isa => 'ArrayRef') ;
13              
14             our $VERSION = '0.08';
15              
16             sub BUILD {
17             my($self)=@_;
18             $self->replacements([]);
19             }
20              
21             sub DESTROY {
22             my($self)=@_;
23             $self->elem->replace_with( @ { $self->replacements } ) ;
24             }
25              
26             sub push_clone {
27              
28             my($self)=@_;
29              
30             my $clone = $self->elem->clone;
31             push @{$self->replacements}, $clone;
32              
33             $clone;
34             }
35              
36              
37             1; # End of HTML::Element::Replacer