XML-OPML-SimpleGen

 view release on metacpan or  search on metacpan

lib/XML/OPML/SimpleGen.pm  view on Meta::CPAN

package XML::OPML::SimpleGen;

use strict;
use warnings;

use base 'Class::Accessor';

use DateTime;

use POSIX qw(setlocale LC_TIME LC_CTYPE);

__PACKAGE__->mk_accessors(qw|groups xml_options outline group xml_head xml_outlines xml|);

# Version set by dist.ini; do not change here.
our $VERSION = '0.07'; # VERSION

sub new {
    my $class = shift;
    my @args = @_;

    my $args = {
	    groups  => {},

	    xml     => {
	        version     => '1.1',
	        @args,
	        },			

	    # XML::Simple options
	    xml_options => {
	        RootName    => 'opml', 
	        XMLDecl     => '<?xml version="1.0" encoding="utf-8" ?>',
	        AttrIndent  => 1,
	    },

	    # default values for nodes
	    outline => {
	        type        => 'rss',
	        version     => 'RSS',
	        text        => '',
	        title       => '',
	        description => '',
	    },

	    group => {
	        isOpen      => 'true',
	    },

	    xml_head        => {},
	    xml_outlines    => [],

	    id              => 1,
    };

    my $self = bless $args, $class;

    # Force locale to 'C' rather than local, then reset after setting times.
    # Fixes RT51000.  Thanks to KAPPA for the patch.
    my $old_loc = POSIX::setlocale(LC_TIME, "C");
    my $ts_ar = [ localtime() ];
    $self->head(
        title => '',
        $self->_date( dateCreated  => $ts_ar ),
        $self->_date( dateModified => $ts_ar ),
    );
    POSIX::setlocale(LC_TIME,$old_loc);

    return $self;
}

sub _date {
  my $self  = shift;
  my $type  = shift; # dateCreated or dateModified.
  my $ts_ar = shift; # e.g [ localtime() ]

  my %arg;
  @arg{qw(second minute hour day month year)} = (
      @{$ts_ar}[0..3],
      $ts_ar->[4]+1,
      $ts_ar->[5]+1900 );
  my $dt = DateTime->new( %arg );
  return ( $type => $dt->strftime('%a, %e %b %Y %H:%M:%S %z') );
}

sub id {
    my $self = shift;
    
    return $self->{id}++;
}

sub head {
    my $self = shift;
    my $data = {@_};



( run in 1.060 second using v1.01-cache-2.11-cpan-39bf76dae61 )