1 package WebPAC::Output::Jifty;
6 use base qw/WebPAC::Common WebPAC::Output Class::Accessor/;
7 __PACKAGE__->mk_accessors(qw(
13 use Data::Dump qw/dump/;
14 use WebPAC::Common qw/force_array/;
23 WebPAC::Output::Jifty - fill Jifty model from WebPAC data
27 our $VERSION = '0.01';
31 This is simple output which will fill one Jifty model with data
37 my $output = new WebPAC::Output::Jifty({
38 path => '/path/to/Jifty',
39 model => 'Webpacus::Model::UFO',
51 my $log = $self->_get_logger;
53 foreach my $p (qw/path model/) {
54 $log->logdie("need $p") unless ($self->$p);
57 my $path = $self->path;
59 $log->logdie("Jifty path $path not found: $!") unless -d $path;
61 my $config_path = "$path/etc/config.yml";
63 $log->logdie("expected Jifty config at $config_path: $!") unless -e $config_path;
65 my $model = $self->model || confess "no model?";
67 $log->info("init Jifty at $path using model $model");
68 my $webpac_dir = getcwd();
69 chdir $path || $log->logdie("can't chdir($path): $!");
71 chdir $webpac_dir || $log->logdie("can't chdir($webpac_dir): $!");
73 my $system_user = Webpacus::CurrentUser->superuser;
74 $self->{_model} = $model->new(current_user => $system_user);
83 $output->add( 42, $ds );
94 my $log = $self->_get_logger;
95 $log->logdie("need id") unless defined $id;
96 $log->logdie("need ds") unless $ds;
98 $log->debug("id: $id ds = ",sub { dump($ds) });
102 my $hash = $self->ds_to_hash( $ds, 'display', single_values => 1 ) || next;
104 $log->debug("data: ", sub { dump( $hash ) });
106 my ( $m_id, $msg ) = $self->{_model}->load_or_create( %$hash );
107 $log->debug("ID: $m_id $msg");
109 push @{ $stat->{$msg} }, $m_id;
123 my $log = $self->_get_logger;
124 $log->debug("stats: ", dump( $stat ));
131 Dobrica Pavlinusic, C<< <dpavlin@rot13.org> >>
133 =head1 COPYRIGHT & LICENSE
135 Copyright 2007 Dobrica Pavlinusic, All Rights Reserved.
137 This program is free software; you can redistribute it and/or modify it
138 under the same terms as Perl itself.