XML-Tidy-Tiny-0.02/0000755000076500007650000000000011566671144013026 5ustar gtolygtolyXML-Tidy-Tiny-0.02/README0000644000076500007650000000100711566461213013676 0ustar gtolygtolyXML-Tidy-Tiny version 0.01 ========================== INSTALLATION To install this module type the following: perl Makefile.PL make make test make install DEPENDENCIES: None COPYRIGHT AND LICENCE Put the correct copyright and licence information here. Copyright (C) 2011 by A. G. Grishayev This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available. XML-Tidy-Tiny-0.02/lib/0000755000076500007650000000000011566671144013574 5ustar gtolygtolyXML-Tidy-Tiny-0.02/lib/XML/0000755000076500007650000000000011566671144014234 5ustar gtolygtolyXML-Tidy-Tiny-0.02/lib/XML/Tidy/0000755000076500007650000000000011566671144015145 5ustar gtolygtolyXML-Tidy-Tiny-0.02/lib/XML/Tidy/Tiny.pm0000644000076500007650000000724511566670511016433 0ustar gtolygtolypackage XML::Tidy::Tiny; use 5.008001; use strict; use Exporter 'import'; # Items to export into callers namespace by default. Note: do not export # names by default without a very good reason. Use EXPORT_OK instead. # Do not simply export all your public functions/methods/constants. # This allows declaration use XML::Tidy::Tiny ':all'; # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK # will save memory. our %EXPORT_TAGS = ( 'all' => [ qw( xml_tidy ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw( xml_tidy ); our $VERSION = '0.02'; sub xml_tidy{ my $data = shift; my $header =''; $header = $1 if $data=~s/^(<\?.*?\?>)\s*//s; $header .= "\n" if $header; my @data = grep length, split qr{(]+/?>)}, $data, -1; my @pre_push ; my @pre_number; my @pre_level; my $buff = ''; my $level = 0; my $accum; while (@data) { my $item = shift @data; next unless length $item; my $type; if ( $item =~ m/^\z/ ) { # TAG ALONE $type = 0; if (@pre_push) { push @pre_push, $item; } else { $pre_push[0]=~s/^\s+//; $buff .= $_ for "\n", ' ' x $level, @pre_push, $item; @pre_push = (); } } else { $type = 1; if (@pre_push) { # TAG OPEN $pre_push[0]=~s/^\s+//; $buff .= $_ for "\n", ' ' x ( $level - 1 ), shift @pre_push; ++$level; if ( @pre_push ){ $pre_push[0]=~s/^\s+//; $buff .= $_ for "\n", ' ' x ( $level - 1), @pre_push; } @pre_push = $item; } else { ++$level; push @pre_push, $item; } } } else { next if $item=~m/^\s+\z/; if (@pre_push) { push @pre_push, $item; } else { push @pre_push, $item; $pre_push[0]=~s/^\s+//; $buff .= $_ for "\n", ' ' x $level, @pre_push; @pre_push = ( ); } } } if (@pre_push) { $buff .= "\n" if length $buff; $pre_push[0]=~s/^\s+//; $buff .= $_ for ' ' x ( $level ), @pre_push; } $buff=~s/^\s+//; $buff=~s/\s+\z//; return $header . $buff; } # Preloaded methods go here. 1; __END__ # Below is stub documentation for your module. You'd better edit it! =head1 NAME XML::Tidy::Tiny - Tiny XML tidy =head1 SYNOPSIS use XML::Tidy::Tiny; # or use XML::Tidy::Tiny qw(xml_tidy); print xml_tidy( $unformated_xml ); =head1 DESCRIPTION This module allow very restrictive tidy of xml. And don't check validity of xml inputed. =head1 SEE ALSO L =head1 AUTHOR A. G. Grishayev, Egrian@cpan.orgE =head1 COPYRIGHT AND LICENSE Copyright (C) 2011 by A. G. Grishayev This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available. =cut XML-Tidy-Tiny-0.02/MANIFEST0000644000076500007650000000024011566671144014153 0ustar gtolygtolyChanges Makefile.PL MANIFEST README lib/XML/Tidy/Tiny.pm t/00-use.t t/01-usage.t META.yml Module meta-data (added by MakeMaker) XML-Tidy-Tiny-0.02/t/0000755000076500007650000000000011566671144013271 5ustar gtolygtolyXML-Tidy-Tiny-0.02/t/01-usage.t0000644000076500007650000000205611566671006015000 0ustar gtolygtoly# #=============================================================================== # # FILE: 01-usage.t # # DESCRIPTION: # # FILES: --- # BUGS: --- # NOTES: --- # AUTHOR: YOUR NAME (), # COMPANY: # VERSION: 1.0 # CREATED: 05/23/2011 05:15:16 PM # REVISION: --- #=============================================================================== use strict; use warnings; use Test::More 'no_plan'; # last test to print use ExtUtils::testlib; use XML::Tidy::Tiny qw(xml_tidy); is( xml_tidy('123'), '123' ); is( xml_tidy('123'), '123' ); is( xml_tidy('123456'), '123456' ); is( xml_tidy('123'), "\n 123\n" ); is( xml_tidy('123'), "\n123" ); is( xml_tidy( '9123'), "\n 9\n 123\n"); is( xml_tidy( ' '), ''); TODO: { local $TODO = "next version"; my $x; }; XML-Tidy-Tiny-0.02/t/00-use.t0000644000076500007650000000107211566456712014471 0ustar gtolygtoly# Before `make install' is performed this script should be runnable with # `make test'. After `make install' it should work as `perl XML-Tidy-Tiny.t' ######################### # change 'tests => 1' to 'tests => last_test_to_print'; use Test::More tests => 3; BEGIN { use_ok('XML::Tidy::Tiny') }; BEGIN { use_ok('XML::Tidy::Tiny', 'xml_tidy') }; can_ok( 'XML::Tidy::Tiny' , 'xml_tidy' ); ######################### # Insert your test code below, the Test::More module is use()ed here so read # its man page ( perldoc Test::More ) for help writing this test script. XML-Tidy-Tiny-0.02/Changes0000644000076500007650000000034311566666472014331 0ustar gtolygtolyRevision history for Perl extension XML::Tidy::Tiny. 0.02 2011-05-24 - Make TODO Test 9 123 0.01 2011-05-23 - original version; created by h2xs 1.23 with options XML-Tidy-Tiny-0.02/Makefile.PL0000644000076500007650000000076311566455433015007 0ustar gtolygtolyuse 5.008001; use ExtUtils::MakeMaker; # See lib/ExtUtils/MakeMaker.pm for details of how to influence # the contents of the Makefile that is written. WriteMakefile( NAME => 'XML::Tidy::Tiny', VERSION_FROM => 'lib/XML/Tidy/Tiny.pm', # finds $VERSION ($] >= 5.005 ? ## Add these new keywords supported since 5.005 (ABSTRACT_FROM => 'lib/XML/Tidy/Tiny.pm', # retrieve abstract from module AUTHOR => 'A. G. Grishayev ') : ()), ); XML-Tidy-Tiny-0.02/META.yml0000664000076500007650000000100711566671144014277 0ustar gtolygtoly--- #YAML:1.0 name: XML-Tidy-Tiny version: 0.02 abstract: Tiny XML tidy author: - A. G. Grishayev license: unknown distribution_type: module configure_requires: ExtUtils::MakeMaker: 0 build_requires: ExtUtils::MakeMaker: 0 requires: {} no_index: directory: - t - inc generated_by: ExtUtils::MakeMaker version 6.56 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4